This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-28
Channels
- # announcements (30)
- # architecture (9)
- # aws (2)
- # babashka (23)
- # beginners (55)
- # cider (22)
- # clj-kondo (40)
- # clojure (47)
- # clojure-europe (4)
- # clojure-france (2)
- # clojure-italy (17)
- # clojure-nl (16)
- # clojure-norway (1)
- # clojure-sanfrancisco (1)
- # clojure-seattle (1)
- # clojure-spec (12)
- # clojure-uk (34)
- # clojured (3)
- # clojurescript (15)
- # core-async (11)
- # cursive (19)
- # data-science (3)
- # emacs (7)
- # events (4)
- # figwheel-main (10)
- # fulcro (33)
- # graalvm (49)
- # graphql (11)
- # instaparse (1)
- # java (7)
- # kaocha (1)
- # leiningen (7)
- # malli (3)
- # meander (69)
- # pathom (9)
- # re-frame (4)
- # rum (2)
- # shadow-cljs (34)
- # spacemacs (9)
- # sql (29)
- # tree-sitter (1)
- # yada (3)
I'm trying to figure out how the overrides map for (s/gen)
works, namely for overriding a generator that's down the tree a bit. That is, I have a top level spec ::data
which has a key ::things
which is a collection of ::thing
, which has a key ::properties
. I'm generating the top level - ::data
- and wanting to override both ::things
so I get only 1 thing, and ::properties
so I get an empty list. using (s/gen ::data {::things #(s/gen (s/coll-of ::thing :min-count 1 :max-count 1))})
, I'm able to force ::things
to only have 1 ::thing
, but I haven't figured out the incantation needed to have ::properties
be empty.
The docstring talks about providing a vector of keyword paths, but I haven't been able to find any more detail on what those paths should look like. I've been trying various combinations
I suspect the issue is in using (s/coll-of)
- for now I'm using an spec.gen/fmap
call to remove any extra data I don't want, but would prefer to be able to just generate only the data needed
Your s/gen
override for ::things
could have a third argument which is the override for ::properties
A bit like this
(s/exercise ::things 10 {::things #(s/gen (s/coll-of ::thing :min-count 1 :max-count 1) {::properties (fn [] (s/gen (s/coll-of string? :min-count 0 :max-count 0)))})})
I would have expected to be able to use [::properties]
as a key in the top-level overrides but that doesn't seem to work.
I can't figure it out from the code 😕
s/keys
and several others build a vector of keys to index into the overrides
but I got lost trying to trace through multiple layers
I think it's because the nested s/gen
creates a different context that doesn't know about the overrides in the top level s/exercise
^^ this, there's actually a bug around this iirc