Fork me on GitHub
James Vickers01:11:32

Is there a 'normal' way to use function specs in your automated test suite? I feel like I haven't found a good solution to this - likely because I haven't written a regular test.check suite either.


wrapping a call in clojure.test/is is pretty easy

James Vickers02:11:55

I was wondering if there was already (`test.check`?) library function that would do something like that (some 'idiomatic' way).

James Vickers02:11:40

Is using function specs in the test suite a normal thing that people do, or are folks just using spec for development time help?


I would certainly put them in the test suite if I were using spec


@jamesvickers19515 We use spec in all sorts of ways. We use it heavily in production code for validating and conforming input parameters, specifying data structures (and then leveraging the form of the spec to "reflect" and get the set of keys that are "permitted", e.g., when storing hash maps in a SQL table), in tests via s/instrument, in tests via s/exercise to generate conforming test data.


In some cases we use test.check as part of a regular test, but generally we have those as separate tests we run apart from our unit tests -- generative testing often takes quite a while so it probably shouldn't be part of your unit test suite.


I'm seeing an inconsistency between Clojure and ClojureScript for multi-arity fdefs.


That spec catches the errors just fine, on Clojure, for all the arities. On ClojureScript, bad calls don't get caught by instrumentation at all.


Updated the gist; looks like a simple defn, with the same spec, throws for both cases (as it should). So this is specific to something happening in ClojureScript's multi-arity defn.


(def color-regex #"^#[0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z][0-9a-z]")

(s/def ::stroke-color (s/and string? #(re-matches color-regex %)))

(s/valid? color-regex "#ffaa88")

what am I doing wrong here, it is complaining that regex can not be converted into a function


the last line should be: (s/valid? ::stroke-color ...)