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
Q: consider following snippet:
(s/valid? (s/keys :req [:nexus.annotation/id]) {:nexus.annotation/id 1
:nexus.annotation/annotation-set {:invalid :map}}) => false
1. Why does spec take the second (invalid) key into account? 2. Is there a way to make spec ignore the second key
Apparently this is by design:
> > 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.
yes, it is by design
attributes have global meaning