clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
jumar 2020-06-18T03:36:47.375900Z

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

seancorfield 2020-06-18T03:56:06.377200Z

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

seancorfield 2020-06-18T03:58:05.378400Z

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.

jumar 2020-06-18T04:29:41.379Z

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

seancorfield 2020-06-18T04:37:30.379300Z

No. Why would you?

seancorfield 2020-06-18T04:37:48.379800Z

You want instrumentation in place for testing, not production.

Scott Silver 2020-06-18T17:57:22.386200Z

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

seancorfield 2020-06-18T18:03:43.386400Z

I run tests during dev so... ๐Ÿ™‚

seancorfield 2020-06-18T18:05:12.386600Z

(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 Silver 2020-06-18T18:06:08.386800Z

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?

seancorfield 2020-06-18T18:09:27.387Z

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

seancorfield 2020-06-18T18:10:12.387300Z

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.

1๐Ÿ‘
jumar 2020-06-18T05:38:16.383100Z

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-john 2020-06-18T13:11:55.384400Z

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?

alexmiller 2020-06-18T13:29:07.385700Z

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

2๐Ÿ‘
Scott Silver 2020-06-18T17:57:22.386200Z

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

seancorfield 2020-06-18T18:03:43.386400Z

I run tests during dev so... ๐Ÿ™‚

seancorfield 2020-06-18T18:05:12.386600Z

(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 Silver 2020-06-18T18:06:08.386800Z

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?

seancorfield 2020-06-18T18:09:27.387Z

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

seancorfield 2020-06-18T18:10:12.387300Z

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.

1๐Ÿ‘