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
Amir Eldor 2020-05-10T19:49:27.328Z

Hello, rather new to this. How would you instrument specs only in development? I'm using Leiningen, I guess there's some way to check what profile we're running? If so, would you do this (if) at the bottom of each namespace with specs??

seancorfield 2020-05-10T21:37:28.330300Z

@amir In several of my projects, I have the tests run with instrumentation in place, so each test file has a test fixture that turns instrumentation on (or just a top-level form that does it as the test file is loaded). Since I tend to be loading/running tests a lot during development, that usually means I have instrumentation turned on during development -- but it's easy enough to just eval an instrument call from a comment in your source file.

seancorfield 2020-05-10T21:38:42.331600Z

Not sure what profiles have to do with that. If I'm developing, I'm working with a REPL. If I'm testing, I can have the tests turn instrumentation on. Otherwise the code won't turn instrumentation on by default, which is the behavior I want.

seancorfield 2020-05-10T21:39:19.332100Z

We use Specs heavily in production as well -- see https://corfield.org/blog/2019/09/13/using-spec/

1🤘
2020-05-14T17:10:25.406500Z

this is super useful, thanks for the post! I have a use case where I want to generate some crud operations as well for some map specs - do you have any pointers for functions you used to parse the specs? I see s/describe and s/form did you use those or something else?

seancorfield 2020-05-14T17:38:20.406700Z

Just those. To get at the primary list of required/optional keys.

2020-05-14T17:41:31.406900Z

perfect, thanks!