This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-30
Channels
- # beginners (126)
- # boot (2)
- # cider (6)
- # cljs-dev (46)
- # cljsjs (8)
- # clojure (122)
- # clojure-greece (57)
- # clojure-italy (6)
- # clojure-poland (3)
- # clojure-russia (2)
- # clojure-serbia (5)
- # clojure-spec (26)
- # clojure-uk (99)
- # clojurescript (39)
- # cursive (15)
- # datascript (7)
- # datomic (21)
- # dirac (7)
- # duct (1)
- # emacs (19)
- # fulcro (58)
- # garden (4)
- # graphql (15)
- # hoplon (2)
- # immutant (1)
- # instaparse (3)
- # jobs (5)
- # juxt (15)
- # klipse (4)
- # leiningen (2)
- # lumo (52)
- # off-topic (8)
- # om (27)
- # onyx (22)
- # other-languages (3)
- # portkey (2)
- # protorepl (2)
- # re-frame (7)
- # reagent (7)
- # ring (11)
- # rum (7)
- # shadow-cljs (114)
- # spacemacs (20)
- # specter (16)
- # test-check (5)
- # timbre (1)
- # unrepl (43)
- # yada (17)
I'm trying to hook a custom generator to a spec and I can't quite get it working - I suspect it's something simple that I'm missing. Details in thread.
My custom generator is
(def gen-7-digit-plan (gen/fmap #(apply str %)
(gen/tuple (gen/choose 0 9)
(gen/choose 0 9)
(gen/choose 0 9)
(gen/choose 0 9)
(gen/choose 0 9)
(gen/choose 0 9)
(gen/choose 0 9))))
Spec is (s/def ::plan (s/with-gen string? gen-7-digit-plan))
Error message starts with #object[TypeError TypeError: self__.gfn.call is not a function]
What I'm actually looking for is a 7 digit string with a range from 0000000
to 9999999
- probably there's a way better way to do this.
I know test.chuck lib has regex->string generators https://github.com/gfredericks/test.chuck#string-from-regex
Awesome, thanks!
@shaun-mahood I might be wrong, but it seems like every gen override place in spec expects no args fn returning actual generator, hence “constantly” above.
I'm trying to spec clojure.string/index-of
(defn- str-or-char? [s] (or (string? s) (char? s)))
(s/fdef clojure.string/index-of
:args (s/alt :idx (s/cat :s string?
:value str-or-char?)
:idx+from (s/cat :s string?
:value str-or-char?
:from-index int?))
:ret (s/nilable int?))
but running into this weird exception when instrument
(stest/instrument)
(clojure.string/index-of "abc" "a" 0)
;=> CompilerException java.lang.ClassCastException: clojure.spec.test.alpha$spec_checking_fn$fn__2943 cannot be cast to clojure.lang.IFn$OOLO
@quan I believe that happens when you try to instrument a function that has arguments type-hinted to primitives. The IFn$OOLO type is (Object, Object, long) -> Object and is optimized for the primitive argument and that breaks spec. It's a known issue (I don't recall the JIRA issue number).
I want to use spec generators to build sample data when I'm prototyping a front end app. The generators return nil when I try to use them at runtime after requiring the file, but they work fine if I run them directly in the repl. Is there a good way to get these to work at runtime?
@shaun-mahood I might be wrong, but it seems like every gen override place in spec expects no args fn returning actual generator, hence “constantly” above.
Hi. I’m using spec to validate data being prepared for transactions on datomic, including tempid’s. All works good. There is now a spec registered for :db/id that checks to make sure it is a instance of datomic.db.DbId. Wonderful, and I even created a custom generator. However, now when I am using spec with data read in, I have data with :db/id 123345, rather than a instance of datomic.db.DbId. This obviously fails the spec in instrumentation. It seems as though I need two versions of the spec for :db/id but this cannot be, in my understanding. Anyone tried anything similar?
(s/def ::uuid (s/or :int integer? :uuid uuid? :sha256 ::sha256))
your spec is not capturing all the possible forms of :db/id
has anyone got a tidy way of writing core.test is checks of spec/check? I've got something that works, but it's pretty ugly!
is it uglier than this?
(is (not (:check-failed (st/summarize-results (st/check `foo)))))