Fork me on GitHub
#clojure-spec
<
2017-08-23
>
didibus01:08:04

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

didibus02:08:34

great, thx

didibus03:08:47

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?

didibus03:08:51

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

martinklepsch10:08:57

Hey all 🙂

martinklepsch10:08:34

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

martinklepsch10:08:28

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

rod10:08:27

Do you have a repo you can link to martinklepsch?

martinklepsch10:08:46

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

martinklepsch10:08:17

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

jrychter17:08:55

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

jrychter17:08:51

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.

jrychter17:08:43

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

potetm18:08:21

Thanks for the tip @alexmiller!

bbrinck20:08:42

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

adamfrey20:08:26

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

jebberjeb20:08:34

@bbrinck PRs welcome there 🙂