Add Spec to a projectλ︎
Create a new project or clone practicalli/leveraging-spec which includes several examples of using Clojure Spec.
Create a new Clojure CLI project using the Practicalli project templates
Practicalli Clojure CLI Config - :project/create alias
Practicalli Clojure CLI Config repository includes the :project/create
alias for creating new Clojure projects from a template using deps-new
.
The project is created with Clojure as a dependency, which includes the clojure.spec.alpha
library.
Clojure 1.9.0 or higher versions include Clojure Spec. Clojure 1.11.1 is recommended.
practicalli/leveraging-spec project includes Clojure Spec examples for values and functional arguments, along with unit tests using clojure spect-test.
Project Dependenciesλ︎
Clojure Spec is included in Clojure so only org.clojure/clojure
dependency is required in the deps.edn
file for the project.
Clojure project dependency
Use spec in namespaceλ︎
Require the clojure.spec.alpha
namespace in the ns
definition using the spec
alias name. Practicalli recommends using spec
(rather than s
as it is much clearer as to where the functions are defined)
Clojure project dependency
Evaluate the namespace definition to start using the functions from the namespace.
All functions from clojure.spec.alpha
are now accessible using the spec
alias, e.g. spec/conform
, spec/valid?
, spec/def
.
Testing with specλ︎
Add the clojure.spec.test.alpha
using the spec-test
alias, along with clojure.spec.test.alpha
as spec
alias