Fork me on GitHub
#clojure-spec
<
2020-05-10
>
Amir Eldor19:05:27

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??

seancorfield21:05:28

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

seancorfield21:05:42

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.

seancorfield21:05:19

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

metal 4
dvingo17:05:25

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?

seancorfield17:05:20

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

dvingo17:05:31

perfect, thanks!