Fork me on GitHub

Am I right in thinking that the generator for (s/keys :req [(or ::a ::b ::c)]) will always return a map with all keys? I think that will leave out potential edge cases when doing generative testing.

Alex Miller (Clojure team)02:08:28

there is a pending enhancement to fix that


great, thx


Question: I've got a spec which is a map-of string? to itself. It works, but sometimes the generator takes like 5 seconds or more to generate a single example. Is there a way I can limit the number of recursive generation it does?


(s/def :a/b (s/map-of string? (s/or :1 :a/b
                                                               :2 string?)))


I’m getting errors when starting my repl: clojure.lang.ExceptionInfo: Unable to resolve spec: :app.spec/thing


I require my app.spec namespace in my main namespace so I’m thinking it should be loaded before other namespaces depending on it.


Do you have a repo you can link to martinklepsch?


@rod unfortunately not but I may have just found the issue


another namespace except core required app.spec resulting in it (+ some others) being loaded before the spec namespace was loaded


I just realized that multi-specs use the raw data, not conformed data, for their multimethods. I didn't expect that, but now that I think about it, it seems it's the only way to avoid dependency issues. Is this expected, or am I doing something silly? To clarify what I'm talking about:

(s/def ::type (s/and (s/conformer keyword) keyword?))
(defmulti part-type :type)
(defmethod part-type "meta" [_]
The defmethod has to be defined on "meta", not :meta, because that's what the database returns and that's what the value is before conforming.

Alex Miller (Clojure team)17:08:43

that seems like the expected behavior to me

Alex Miller (Clojure team)17:08:31

multi-spec chooses a spec based on the data

Alex Miller (Clojure team)17:08:51

note that the multimethod does not need to be based on a keyword though, it can be an arbitrary function


Yes, after thinking about this for a moment, I realized that it would be unreasonable to expect anything different. And yet it surprised me, I grew used to thinking of conform as a conversion layer between database representation (JSON in my case) and native Clojure data. I expect the "conversion" to happen first, before the method gets selected.


I think I read somewhere that s/conform isn't really intended for this role, but I find it amazingly useful.


Thanks for the tip @alexmiller!


Does anyone know of work to generate human-readable documentation from specs?


it is possible to set the generator of a spec after it's been defined?

Alex Miller (Clojure team)20:08:06

@adamfrey not without re-registering it

Alex Miller (Clojure team)20:08:04

@bbrinck autodoc is used to create the clojure docs and it has rudimentary support for including specs

Alex Miller (Clojure team)20:08:31

there are also one (or maybe more) tools for creating diagrams representing specs


@bbrinck PRs welcome there 🙂