Clojure Spec for data
Specifications can be defined for any data in Clojure, be that simple values or complex data structures. More complex specifications are composed of individual specifications, providing a flexible way to define specifications without building a brittle hierarchy.
What is a specification
There are many predicate functions that come with Clojure which help speed the creation of specifications. Clojure function definitions (
defn) can be used to define custom predicate functions too.
Do values meet a specification
conform- test if data conforms to a specification, returning the conformed value
valid?- predicate to test if data conforms to a specification, returning true of false
explain- explain why a value is not conforming to a specification
Workflow for data specifications
The generative tests section shows how specifications are used to generate mock data, so creating specifications earlier on in the development process will provide a wider range of data for unit tests and repl experimentation.