This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-13
Channels
- # bangalore-clj (1)
- # beginners (29)
- # boot (13)
- # braveandtrue (5)
- # clara (5)
- # cljs-dev (42)
- # cljsrn (7)
- # clojure (55)
- # clojure-france (46)
- # clojure-nl (11)
- # clojure-portugal (1)
- # clojure-russia (268)
- # clojure-spec (26)
- # clojure-uk (32)
- # clojurescript (173)
- # clr (2)
- # core-async (46)
- # cursive (22)
- # datomic (33)
- # devcards (1)
- # emacs (5)
- # events (8)
- # figwheel (2)
- # flambo (4)
- # instaparse (8)
- # jobs (11)
- # klipse (46)
- # lein-figwheel (3)
- # london-clojurians (2)
- # nrepl (1)
- # off-topic (29)
- # om (4)
- # om-next (8)
- # pedestal (3)
- # rdf (4)
- # re-frame (51)
- # reagent (104)
- # remote-jobs (1)
- # rum (4)
- # schema (2)
- # specter (19)
- # untangled (16)
- # vim (52)
That complicates things but there are some features you might like to check out. Pretty sure you can stub out functions. That might let you isolate you're logic for testing.
I haven't used that feature myself.
@dbushenko Attach the spec as a validator to the var/ref/agent/atom, maybe... https://clojuredocs.org/clojure.core/set-validator!
@dbushenko @olivergeorge regarding stubbing a function — after fdef
ing the function, use
(stest/instrument `your-func {:stub #{`your-func}})
to use the :ret
in the fdef
instead of calling the real function, fyievery
doesn’t use res
on its element predicate argument:
=> (s/form (s/every string?))
(clojure.spec/every
string?
:clojure.spec/kind-form
nil
:clojure.spec/cpred
#object[user$eval8666$fn__8668 0x5ba5f0bd “user$eval8666$fn__8668@5ba5f0bd"])
I’ve found http://dev.clojure.org/jira/browse/CLJ-2035 which covers that but with a larger scope.
@alexmiller Would it be sensible to open a ticket just for the resolution of the predicate?No, please add to 2035 if it's not already covered by the patch there
I think there may actually be another ticket for this already though
Nah, I was thinking of 2059 which is in explain-data
you can always write arbitrary predicates that check whatever you want
Hi, I have a list of maps and each map has an :idx key which is an int. Now what I want is that given one list every :idx is a unique int. Is there a way to enforce that?
@sveri the collection spec have a :distinct option
Although I guess that goes farther than you want
Hi here! Let’s say I’ve got a map of user. The key ::password
must be present if and only if a user is new (the key ::new?
is bound to a truthy value). Is it possible to express this with clojure.spec
?
@alexmiller I have seen that, but I suspect it means distinct for the whole map and not only for the :idx key
@piotr2b: sure, use a custom predicate
@mss if you can convert to clojure data structures first then you'll get access to more spec features. In particular s/keys & all the standard generators
@sveri test.check has distinct-by
generators for that sort of thing; I don't know if spec exposes it in the collection specs or not