This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-03
Channels
- # announcements (4)
- # beginners (68)
- # boot (3)
- # business (20)
- # cider (39)
- # cljs-dev (7)
- # cljsjs (1)
- # cljsrn (12)
- # clojure (122)
- # clojure-brasil (2)
- # clojure-italy (7)
- # clojure-nl (5)
- # clojure-spec (60)
- # clojure-uk (41)
- # clojurescript (67)
- # cursive (7)
- # datomic (13)
- # emacs (6)
- # figwheel-main (18)
- # fulcro (40)
- # garden (3)
- # graphql (2)
- # hyperfiddle (4)
- # jobs-discuss (10)
- # lein-figwheel (5)
- # leiningen (12)
- # luminus (6)
- # mount (3)
- # off-topic (52)
- # portkey (2)
- # re-frame (1)
- # reagent (6)
- # reitit (24)
- # shadow-cljs (15)
- # sql (3)
- # tools-deps (12)
Hello all, can I ask newbe question here? 🙂 I´m trying to figure out how to use spec in my projects.
Like I saw in this article https://blog.taylorwood.io/2017/10/15/fspec.html , so defn
-> s/fdef
-> stest/instrument
-> stest/check
?
hey @fabrao, an example of how you might use it: have some defn
s you want to spec, write some specs/`fdef`s for those, then in a test namespace you might use check
as part of a test
no, instrument
has a performance penalty, and anywhere I need to use spec "all the time" then I use the explicit conform
/`valid?` kind of functions
like if I wanted to throw an exception because of invalid input? Probably use ex-info
and maybe put some of the s/explain-data
into the info map
in some cases yeah I might call s/conform
or s/explain-data
or s/assert
from my "normal" code
probably not as often as the others, because I'm usually also interested in how/why the input was invalid
yeah, overall I don't have many places in my projects where I'm explicitly interacting with spec in my app code/logic
Yes, I saw many videos about it, but only shows something using valid?
and nothing about the use like in your article
do you think is it too intrusive doing this? https://gist.github.com/borkdude/8d69f326b3d363a0b34e7b949b039992
I think that's fine (and it's cool that it's even possible) if that's your workflow, although personally I would probably just use regular defn
and fdef
s
it's really up to how you want to use spec and structure your code :man-shrugging: try some different approaches and see what you like
Yes, I understood, thanks for your time. I´d appreciate all the subjects of your blog, all subject that I sometimes worked with
you might choose to enable instrumentation for particular tests by calling instrument
, or maybe in a dev profile so everything is instrumented at dev time
@fabrao The other thing to bear in mind with spec is that there are two related but separate types of spec: data specs and function specs. At work, we rely heavily on the former in production code, where we call s/conform
(mostly) and s/valid?
on those specs and some data. We use function specs to support testing, either with st/instrument
while we're developing or as part of a "unit test", or with st/check
mostly while we're developing but also in small, limited tests (generative testing can take a while so it's not really designed as part of your short, fast "unit test" cycle).
We've been using spec in production pretty much since the first alpha dropped, back in the early 1.9 days. We love it!
That appeared long after we were already on 1.9 and using spec in production tho' 🙂
@seancorfield I saw that we can use s/conform
to contruct maps from data in more easy way
@fabrao Be careful about coercions and conformers in spec tho' -- consider those "very advanced" usage until you're comfortable with the rest of it in your workflow.
If you bake a coercion into your spec, you are "forcing" that coercion on all clients of the spec -- and it may have consequences for generators / generative testing.
But, yeah, overall spec is awesome!
to verify an fdef I think you need to use instrument to explicitly turn on verification
also beware of instrumenting functions that take function arguments - the spec is checked by passing various generated data to the function that was passed in
instrument turns on the validation of the function's spec, it's something you have to explicitly ask for
if you want to ensure that a specific arg is always checked, you can use s/valid? as a predicate, or s/conform if you want an error for non-matching data