Fork me on GitHub

Is it possible to express the following in spec: f accepts a function g from string? to int? and it is also possible to generate random instances of g?


I wondered about this after playing with Quickcheck in Haskell, which can do this


@borkdude (s/fdef f :args (s/cat :g (s/fspec :args (s/cat :str string?) :ret int?)))


@luxbock Looks good. How about the generational aspect?

Alex Miller (Clojure team)20:05:22

Gen of fspec is a function that uses its ret generator


How would I register (and then use) specs that were generated dynamically? I think I’m at the stage where I need to start property testing spec-provider. To do this I need to generate random data (possible), infer specs for them (that’s what the lib does) and then validate that all the random data are valid for those inferred specs.

Alex Miller (Clojure team)22:05:45

Well you can either call s/def and register your specs or you can just call conform on the specs directly without registering, which works for a lot of stuff