This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-14
Channels
- # aleph (14)
- # bangalore-clj (2)
- # beginners (39)
- # boot (18)
- # carry (7)
- # cider (37)
- # cljs-dev (1)
- # cljsrn (4)
- # clojure (74)
- # clojure-austin (12)
- # clojure-canada (6)
- # clojure-conj (15)
- # clojure-dev (3)
- # clojure-greece (14)
- # clojure-italy (1)
- # clojure-korea (1)
- # clojure-poland (3)
- # clojure-russia (5)
- # clojure-spec (22)
- # clojure-uk (13)
- # clojurebridge (9)
- # clojurescript (231)
- # cursive (2)
- # datascript (9)
- # datomic (12)
- # devcards (2)
- # emacs (2)
- # events (4)
- # hoplon (28)
- # off-topic (35)
- # om (61)
- # onyx (8)
- # parinfer (8)
- # proton (1)
- # re-frame (53)
- # reagent (10)
- # ring-swagger (8)
- # specter (11)
- # untangled (3)
- # vim (4)
I don't know - try it? You can specify a generator too
yep, generating works fine with :kind sequential?
fyi, snippets
slow down slack a lot. Maybe we should default to creating posts
instead of snippets
.
I keep having to with-gen
or overspecify my generator in clojurescript as generation just takes too long and eventually times out.
> (defn fx [coll] coll)
> (s/fdef fx :args (s/cat :coll coll?))
> (stest/summarize-results (stest/check `fx))
Have you tried using the :gen-max option?
For spec'ing collections that is
You could use (s/coll-of any? :gen-max 3)
i’m looking at doing form validation using spec. any thoughts on mapping from an explain to a slightly more human readable messages to put under fields? can’t find anything to put metadata on
hmm, looks like i’d need to key off the pred symbol actually
user=> (s/explain-data (s/keys :req [::foo]) {::foo ""})
#:clojure.spec{:problems ({:path [:user/foo], :pred not-empty, :val "", :via [:user/foo], :in [:user/foo]})}
@alexmiller Thank you for your help. I played around with it since then. Actually, the real issue was that I was including a spec in the :ret
part of my s/fdef
. This causes the value in :ret
in the :fn
part of the same s/fdef
to be the spec-conformed-return version of the :ret
, not the function-value-return version of the return. Kept causing failures that I just couldn’t understand. 🙂
tldr; If your spec does not conform to the identity of the value passed to it, you should think about what you are doing when using it in s/fdef
’s :ret
hrm, wrapping it in s/and allows you to retrieve the “ground” spec:
cljs.user=> (cljs.spec/explain-data (cljs.spec/keys :req [::foo]) {::foo ""})
{:cljs.spec/problems {[:cljs.user/foo] {:pred not-empty?, :val "", :via [:cljs.user/foo], :in [:cljs.user/foo]}}}
cljs.user=> (cljs.spec/def ::foo (cljs.spec/and ::not-empty))
:cljs.user/foo
cljs.user=> (cljs.spec/explain-data (cljs.spec/keys :req [::foo]) {::foo ""})
{:cljs.spec/problems {[:cljs.user/foo] {:pred not-empty?, :val "", :via [:cljs.user/foo :cljs.user/not-empty], :in [:cljs.user/foo]}}}