Fork me on GitHub
#clojure-spec
<
2020-06-18
>
jumar03:06:47

@scott.silver asked this in #cider: https://clojurians.slack.com/archives/C0617A8PQ/p1592435925498900 I'm also curious what's your approach with stest/instrument and evaluating a clojure buffer since it must be a problem with other editors too. In short, after you evaluate a ns buffer all the instrumentation is gone and you need to call instrument again manually which is cumbersome and easy to forget. Developers then commit spec errors which are only found much later, etc.

seancorfield03:06:06

If I'm using instrument with dev/test, I have a call to instrument as part of each test namespace. See https://github.com/seancorfield/next-jdbc/blob/develop/test/next/jdbc_test.clj#L21 (and similar lines in every test ns in next.jdbc).

seancorfield03:06:05

You could make it part of you fixtures if you wanted to ensure it was added for every test you ran via the REPL from your editor but I think this is enough to ensure a full test run uses specs.

jumar04:06:41

Interesting, but I'm more worried about real "src" namespaces, rather than tests... do you have instrument calls there as well?

seancorfield04:06:30

No. Why would you?

seancorfield04:06:48

You want instrumentation in place for testing, not production.

Scott Silver17:06:22

I agree that you don’t want it in production, but it’s very useful in dev, not just in test, yeah?

seancorfield18:06:43

I run tests during dev so... 🙂

seancorfield18:06:12

(also, I only spec API boundaries in general, or functions that have some unusual aspects -- we have over 600 specs in our code but only 30-some function specs)

Scott Silver18:06:08

do you run tests manually while developing? or do you use something like lein-test-refresh to run the test suite when you make changes?

seancorfield18:06:27

I have hot keys bound to run: a) all tests in the current namespace b) all tests in a test namespace that corresponds to the current namespace c) the test under the cursor

seancorfield18:06:12

So it is manual but very easy. I don't use lein at all and I don't like watcher-based tasks or any sort of reload/refresh workflow.

👍 3
jumar05:06:16

We enable instrumentation for all fdef-s in dev mode (when running in REPL) to catch issues early - it's not enabled in production

practicalli-john13:06:55

I am assuming the following ways to define a spec are equivalent ? The seem to provide the same results with confirm/valid? etc.

(def suit? #{:clubs :diamonds :hearts :spades})
(spec/def ::suit #{:clubs :diamonds :hearts :spades})
Is it overkill to define a spec for a set as it already acts as predicate function? Or does it make little or no difference?

alexmiller13:06:07

either is fine. s/form probably works better with sets

👍 6