This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-21
Channels
- # beginners (82)
- # bitcoin (1)
- # boot (38)
- # cider (6)
- # cljs-dev (13)
- # cljsrn (5)
- # clojure (320)
- # clojure-italy (22)
- # clojure-losangeles (6)
- # clojure-russia (55)
- # clojure-spec (25)
- # clojure-uk (48)
- # clojurescript (64)
- # component (16)
- # core-async (6)
- # cursive (54)
- # data-science (2)
- # datascript (2)
- # datomic (8)
- # docker (1)
- # ethereum (1)
- # fulcro (1)
- # garden (1)
- # graphql (16)
- # heroku (6)
- # hoplon (12)
- # jobs (4)
- # juxt (1)
- # leiningen (9)
- # off-topic (39)
- # om (13)
- # om-next (2)
- # onyx (9)
- # pedestal (2)
- # portkey (12)
- # re-frame (25)
- # reagent (6)
- # ring-swagger (4)
- # schema (1)
- # shadow-cljs (10)
- # spacemacs (11)
- # testing (19)
- # uncomplicate (1)
- # unrepl (6)
- # vim (21)
- # yada (3)
Hello! I have probably asked this already at some point in the past, but is there a way to create a Generator
that basically uses a function of mine? I am trying with (tcgen/generate (tcgen/->Generator #(faker/name.findName)))
but no luck, it always returns nil
@richiardiandrea what sort of thing are you trying to generate?
fake data generated from a function...it looks like this works:
(def fake-generators
{:order/customer #(tcgen/return (faker/name.findName))})
(gen/generate (s/gen :order/customer fake-generators))
I was basically thinking of it in terms of repeatedly
if you're doing property-based testing at all, it's generally better to build things from the combinators
what does faker/name.findName
do?
well, I am not using it for property testing with this specific case
I am bending it a bit, so that I can generate intelligible data structures
test.check can generate intelligible data structures 🙂
so now I get a very nice:
{:name "saladman",
:key "ia",
:timestamp #inst "1970-01-01T00:00:00.942-00:00",
:aggregate "order",
:data {:customer "Velma Doyle"}}
is this because you want to use the generators for friendly examples?
yep exactly
I almost feel like that should be a different piece of functionality all together
maybe not; I guess it's just the strings that were bothering you?
yes I completely agree with you, it could be a separate piece functionality, but generators by definition can be a good fit for that as well
if I have a restricted set of things I can use tcgen/elements
and that's nice, but for names...something like the above works well
Now I'm thinking this belongs in spec, if anywhere. A function called s/example
which will use custom code if registered and fall back on the generator otherwise
If often find myself redefining fdefs a few times to get them right and AFAICT, you need to call instrument
after each redefinition. Has anyone else run into this? I suppose I could define a new macro named fdef!
that did both steps and then just remove the !
before I commited the code?
some sort of auto-instrumentation mode that worked as I redefined things would be handy. Has anyone written something like this?
@bbrinck I have instrument
called in my user
namespace that is reloaded after all of the other dependencies are loaded
So whenever I reload the code, (with clojure.tools.namespace) there is an instrument call at the end
I still haven't figured out what's the best way to do this for testing though
I've got a lazy way of doing it, which is just to put the instrument call directly in the user
ns, but a fancier way to do it would be to attach it to the c.t.n.r/refresh :after
handler