Fork me on GitHub
#clojure-spec
<
2017-11-12
>
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.

gfredericks01:11:37

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?

gfredericks02:11:10

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

seancorfield02:11:38

@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.

seancorfield02:11:30

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.

jeaye03:11:18

I'm seeing an inconsistency between Clojure and ClojureScript for multi-arity fdefs. https://gist.github.com/jeaye/eaa8da70171a538e23b3c5dbfd9797fd

jeaye03:11:26

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.

jeaye03:11:44

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.

qqq16:11:46

(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

qqq16:11:32

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