Fork me on GitHub
#clojure-spec
<
2020-12-04
>
Sean H00:12:29

Is there a good way to have multiple generators for clojure.spec.test.alpha & clojure.spec.gen.alpha on the same spec on a namespaced keyword? In particular, in cases where we know that a spec is restricted in certain contexts, such as Datomic refs (which when sent TO datomic are either a 2-tuple, an int, or a map [component], while when received FROM datomic are an int or a map). If not, my guess would be the most sensible way to do this is to just override the spec’s generator with a generator that generates the more restrictive form (e.g. int/map in the above example, or just int for non-component refs) and then do generation some other way (or not at all) for cases where you need the more general form? Thanks! EDIT: I think I’ve figured it out. For anyone who’s curious, this can be done by clojure.spec.test.alpha/instrument options

Thomas Moerman17:12:13

Q: consider following snippet:

(s/valid? (s/keys :req [:nexus.annotation/id]) {:nexus.annotation/id             1
                                                :nexus.annotation/annotation-set {:invalid :map}}) => false

Thomas Moerman17:12:47

1. Why does spec take the second (invalid) key into account? 2. Is there a way to make spec ignore the second key

Thomas Moerman17:12:03

Apparently this is by design:

Thomas Moerman17:12:07

> > In addition, the values of all namespace-qualified keys will be validated > (and possibly destructured) by any registered specs. Note: there is > no support for inline value specification, by design.

Alex Miller (Clojure team)18:12:26

attributes have global meaning

3