Fork me on GitHub

Hey all: I'd like make some spec assertions regardless of whether check-asserts has been set. It's important these assertions are always made. To that end I'm looking to use assert*. It's part of the public api, but the doc-string says Do not call this directly, use 'assert'.. Is there something important that I need to know? Seems like it fits the bill otherwise.

Oliver George00:12:29

Could you do something like (asset (s/valid? xxx)) or (binding [s/*assert-flag-thing* true] (s/assert ::x 1)).

Alex Miller (Clojure team)04:12:10

you can use assert* but it’s api is subject to change as part of the implementation - it’s public because it needs to be accessible by the macro when expanded


I'm a complete beginner in clojure-spec, my question is, why don't I get spec error here?

(s/def ::spec1 string?)

(defn silly []

(s/fdef silly
  :ret string?
  :fn string?)



if you’re looking to assert that calls to silly have valid inputs, you can use instrument. Although that’s not going to care about your :ret or :fn function specs


I thought that was done with :args within fdef? I was hoping it would tell me that the number 1 is not string


that’s right, but there’s no :args spec in your example


and you still have to instrument the function for those assertions to happen


ah ok! thanks, I'm reading trough the manual and therefore had this question, I'll continue to read further.


oh, if you’re only concerned about the return value of your function, instrument isn’t going to assert on that. You can use check for that though.


yes that's what I was looking for, but in real world cases I'd see spec being most helpful in the args.


FWIW, Orchestra can be used to check ret/fn specs on instrumentation


@U053S2W0V how is it different from cljs.spec.test.alpha/instrument that said, that's exacly the reason why I want to use spec, to get these errors right away.


instrument only checks the :args


looks like you can use Orchestra to get the same effect for :ret and :fn specs though


ah, nice I see


also like their macros, very neat!