Fork me on GitHub

so how do I stop stest/check from generating NaNs all the time?


the spec that fails is: (s/and number? #(<= 0 % 100))

Alex Miller (Clojure team)14:05:37

do you really need number? ? or is something narrower like int? appropriate?

Alex Miller (Clojure team)14:05:06

it is a known issue right now that NaNs cause issues for certain generators and something we intend to fix


ah ok. I’ll see if int-in works out for me. thanks.

Alex Miller (Clojure team)14:05:04

#(not (Double/isNaN %)) pred may be useful to filter too


Sounds silly but does the order matter inside the s/and


in the NaN example


would you have to have #(not (Double/isNaN %)) second?


then #(<= 0 % 100) last?

Alex Miller (Clojure team)15:05:54

yes, order matters as the first spec generates, then each subsequent one filters, so the order you suggest is probably good


ok thanks!


hi I have , I guess a ‘phlisophical’ lol question about spec. Im working on a system that uses datomic, etc. So, I’d gone though and created a bunch of specs, now I’m building out datomic schemas, using my specs to name my attributes, etc. So of course, some of this isn’t especially DRY. I’m just wondering about creating my own (or using umlaut, etc) lightweight DSL that in turn gen’s datomic schemas, specs, etc. Is this the’right’ way or is starting from specs ‘better’, etc. Just wondering


@eoliphant We wrote a library to do this called Spectomic and have been using it successfully for about a year now.

👍 4
Alex Miller (Clojure team)15:05:29

some people have done this to various degrees

Alex Miller (Clojure team)15:05:46

hard for me to say if they found that to be a win in the long run or not

👍 4

@eoliphant Datomic schema is not the same as a spec. they do similar things - link behaviour to a name, but they are not the same thing (they create different behaviour). conflate them only if you are confident that in doing so, users of your new combined API understand the consequences of this clearly. semantically, they are different. i find i prefer a little extra typing, and having decoupled systems that use very well documented APIs.

👍 4

my hobby project keeps them separate, and i don’t think it actually costs anything to do that


so i guess the question is, are you actually Repeating Yourself? 🙂


So I’ve got nice s/fdef’s for my functions. Is it possible to use those in a test?


I know

(-> (stest/enumerate-namespace 'fca.slipnet.math)


but when I run tests from CIDER it tells me there a no tests defined.


oh, that’s a different question 🙂


So stest/check returns a :clojure.test.check.clojure-test/trial how do I tell clojure.test to look out for it?


yeah that’s kind of the way I was leaning @robert-stuttaford


Hi everyone, new to the channel. Does anyone know of any articles on best practices /process to spec a pre-existing codebase? I know spec, but so far haven't used it much and I have a "not-small" cljs codebase that i want to start spec-ing, but not sure where/how to start...


oh sorry right larger codebases sorry no



Alex Miller (Clojure team)16:05:33

start by writing specs :)

👍 4
Alex Miller (Clojure team)16:05:58

if you have a map that is used a lot, write specs for the attributes

Alex Miller (Clojure team)16:05:13

then write an s/fdef for a function that takes that map

Alex Miller (Clojure team)16:05:46

if you want to know where to start, pick the most common/stable data you have

Alex Miller (Clojure team)16:05:52

work outward from there

Alex Miller (Clojure team)16:05:13

or pick the thing you trust the least and add constraints around it by making specs and using stest/instrument

Alex Miller (Clojure team)16:05:49

if you get an instrument failure, you’ve learned something (either your data does things you didn’t anticipate, or something is wrong)

Alex Miller (Clojure team)16:05:00

if the former, fix your spec. if the latter, fix your code.

Alex Miller (Clojure team)16:05:16

if you have data transformation functions, write specs for the inputs and outputs and use stest/check

Alex Miller (Clojure team)16:05:31

these are ideas, not a plan

👍 8
🙂 4

> or pick the thing you trust the least and add constraints around it by making specs and using stest/instrument ha ha, good one 🙂 i think i ll start there. thanks!


one very useful practice is to spec anything before you make changes. we have code from clojure 1.6 days that we do this to, and it really helps deal with stuff like regression testing, safe refactoring, etc

👍 4

Hey folks, probably a noob question but am really struggling to find an answer via search (probably because of my lack of terminology): If I define a spec using a non auto-resolved keyword (s/def :my/spec any?) how do I use it if I've required that namespace in a separate namespace? I can't get a call to (s/valid? :my/spec 1) to resolve nor does (s/valid? :: 1)

Alex Miller (Clojure team)20:05:09

the latter is not valid

Alex Miller (Clojure team)20:05:17

not a valid keyword that is

Alex Miller (Clojure team)20:05:54

user=> (ns foo (:require [clojure.spec.alpha :as s]))
foo=> (s/def :foo/thing int?)
foo=> (ns bar (:require [clojure.spec.alpha :as s] foo))
bar=> (s/valid? :foo/thing 10)


orz it works now. I think I must have had something else wrong in the file - thanks @alexmiller