This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-31
Channels
- # aws (1)
- # beginners (70)
- # boot (12)
- # calva (45)
- # cider (45)
- # clara (1)
- # cljdoc (10)
- # cljs-dev (133)
- # clojure (315)
- # clojure-dev (2)
- # clojure-europe (2)
- # clojure-italy (16)
- # clojure-nl (1)
- # clojure-spec (23)
- # clojure-uk (19)
- # clojurescript (48)
- # cursive (11)
- # data-science (5)
- # datomic (18)
- # figwheel-main (3)
- # fulcro (18)
- # graphql (14)
- # jackdaw (1)
- # juxt (1)
- # kaocha (1)
- # off-topic (10)
- # other-languages (3)
- # pathom (2)
- # pedestal (7)
- # re-frame (23)
- # reagent (1)
- # reitit (4)
- # ring-swagger (12)
- # rum (4)
- # shadow-cljs (26)
- # specter (6)
- # speculative (12)
- # tools-deps (44)
- # vim (8)
- # yada (2)
FWIW, from spec-alpha2
, latest SHA:
user=> (require '[clojure.spec-alpha2 :as s])
nil
user=> (s/def :user/foo string?)
:user/foo
user=> (s/def :user/bar :user/foo) ;;alias
:user/bar
user=> (s/exercise :user/bar 1 {:user/bar #(s/gen #{"quux"})}) ;;=> (["" ""])
(["" ""])
user=> (s/exercise :user/bar 1 {:user/foo #(s/gen #{"quux"})}) ;;=> (["quux" "quux"])
Execution error (IllegalArgumentException) at clojure.spec-alpha2.protocols/eval173$fn$G (protocols.clj:11).
No implementation of method: :gen* of protocol: #'clojure.spec-alpha2.protocols/Spec found for class: clojure.lang.PersistentHashSet
user=> (s/def :user/bar string?) ;;not alias
:user/bar
user=> (s/exercise :user/bar 1 {:user/foo #(s/gen #{"quux"})}) ;;=> (["quux" "quux"])
(["" ""])
user=>
and your custom generator example:
user=> (s/def :user/foo string?)
:user/foo
user=> (s/def :user/bar (s/with-gen :user/foo #(s/gen #{"bar"})))
:user/bar
user=> (s/exercise :user/bar 1)
Execution error (IllegalArgumentException) at clojure.spec-alpha2.protocols/eval173$fn$G (protocols.clj:11).
No implementation of method: :gen* of protocol: #'clojure.spec-alpha2.protocols/Spec found for class: clojure.lang.PersistentHashSet
user=> (s/exercise :user/bar 1 {:user/bar #(s/gen #{"quux"})})
Execution error (IllegalArgumentException) at clojure.spec-alpha2.protocols/eval173$fn$G (protocols.clj:11).
No implementation of method: :gen* of protocol: #'clojure.spec-alpha2.protocols/Spec found for class: clojure.lang.PersistentHashSet
user=>
I haven’t changed anything since we last talked
That was for @misha not you @alexmiller, since he asked how his code would behave on spec2 🙂
ah, well the thing still to do on aliases for you affects it :)
I'd like to substitute a generator for an "inner" spec while testing. i.e.
;; src file
(s/def ::zip pos-int?)
(s/def ::address (s/keys :req [::zip]))
(s/def ::person (s/keys :req [::address]))
;; test file
(gen/sample (s/gen ::person) 1)
=> {::address {::zip 1}}
;; pseudo code
(gen/sample (redefine-a-spec (s/gen ::person) ::zip #{10001 10002}))
=> {::address {::zip 10001}}
How can I do this?@mattmorten stest/check
also takes an overrides map in case you need that
I have a related question. I have a coll-of ::animal
, where ::animal
is a multi-spec. How do I provide overrides to force the ::animal that is generated?
(s/def ::animal-type #{:dog :cat})
(s/def ::cat-attribute #{"very catty"})
(s/def ::dog-attribute #{"dog dog"})
(defmulti animal-type ::animal-type)
(defmethod animal-type :cat [_] (s/keys :req [::cat-attribute ::animal-type]))
(defmethod animal-type :dog [_] (s/keys :req [::dog-attribute ::animal-type]))
(s/def ::animal (s/multi-spec animal-type ::animal-type))
(s/def ::animals (s/coll-of ::animal))
(s/def ::petshop (s/keys :req [::animals]))
(gen/sample (s/gen ::petshop) 1)
=>(#:{:animals [#:{:cat-attribute "very catty", :animal-type :cat}
#:{:dog-attribute "dog dog", :animal-type :dog}]})
;; How do I override s/gen to get a list of :cat's only?
(gen/sample (s/gen ::petshop {??}) 1)
name the spec returned by the defmethod and override it?
or you’re looking for a particular branch of the multimethod to be poked?
I just need cats!
override ::animal with the generator for the spec returned by (animal-type {::animal-type :cat}) ?
Genius
(gen/sample (s/gen ::petshop {::animal #(s/gen (animal-type {::animal-type :cat}))}) 1)