This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-07
Channels
- # beginners (41)
- # boot (38)
- # cider (17)
- # cljs-dev (52)
- # cljsjs (3)
- # clojure (200)
- # clojure-italy (8)
- # clojure-russia (50)
- # clojure-spec (28)
- # clojure-uk (45)
- # clojurescript (28)
- # core-async (9)
- # core-matrix (2)
- # cursive (16)
- # datascript (15)
- # datomic (50)
- # dirac (5)
- # emacs (20)
- # figwheel (8)
- # flambo (2)
- # hoplon (10)
- # incanter (1)
- # jobs (1)
- # leiningen (2)
- # lumo (26)
- # mount (171)
- # off-topic (22)
- # om (54)
- # onyx (2)
- # pedestal (27)
- # re-frame (10)
- # reagent (12)
- # ring (27)
- # ring-swagger (3)
- # rum (2)
- # slack-help (1)
- # spacemacs (134)
- # specter (6)
- # sql (15)
- # testing (20)
- # uncomplicate (5)
- # unrepl (49)
- # untangled (9)
- # yada (29)
@triss I don't think there is a function for that purpose. But (s/form spec)
give you the spec form, so in your case the list (s/def ::b (s/keys :req-un [::a])
. You could walk it like a tree and recursively s/form
any spec you find until you get a predicate that match you search criteria … I do something similar to extract the set of keys used by nested s/merge
specs. Maybe there is a cleaner way to do it though…
Do you know if there is a way to make spec generate a minimalist sample for a particular spec ?
What I mean by minimalist is "the first simplest value validating the predicate". If I have (s/nilable string?)
I'd like to get nil
, if I have string?
, I'd like to get ""
, if I have (s/coll-of ::foo :kind vector?)
I'd like to get []
.
I don't know (yet) how spec works internally but I would expect it could be able to find the shortest path to the first and simplest value validating the predicate. It would be really useful to generate kind of placeholder data waiting to be filled but still validating the spec. Especially when building forms with Re-Frame or similar frameworks.
Has anyone seen a similar error message like this lately? Attempting to call unbound fn: #’clojure.spec/macroexpand-check We get it in our ClojureScript build. We’re using clojure.future.spec alpha15.
@triss there is no easy way to figure that out right now
@ggaillard you can call gen/sample and take the first example. Samples "grow" in complexity as you use a generator so the first few are usually "simple"
hi, I have a (defspec tester 100....
in my test file... but when I run either lein test
or from the REPL it seems to run only once. Any idea what could cause this?
(s/fdef foo :args (s/cat))
although it may not be worth defining a spec for a no-arg function
as you can’t check its args via instrumentation and generative testing is likely not too useful
well, this method will grow to support multiple parameters, so that's why i wondered in the first place
(s/fdef foo :args (s/* any?))
(with a suitable spec instead of any?) will support 0 or more args
is there a way to make a s/keys
take a var in the req
list?
(let [k :ns/kw] (s/explain (s/keys :req [k]) {:ns/not-kw "hello"})) => Success!
not easily - you can use macro or eval to do so
because s/keys
is a macro and expects a literal vector of keywords in :req
, not something that is evaluated
in the example above, everything that’s not a keyword (`k`) is just being ignored
it’s being interpreted as (s/explain (s/keys :req []) {:ns/not-kw "hello"})