Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Capture domain knowledge once in specs, instead of burying it in tests
;; compare to https://gist.github.com/lensgolda/13e549476fb65d3b8c2d71ca59b15937#file-test-clj
(require '[clojure.spec.alpha :as s])
;; general domain knowledge, not buried in a test
(s/def ::info (s/keys :req-un [::name]))
(s/def ::items (s/coll-of pos-int?))
(s/def ::active boolean?)
;; knowledge specific to this test data
(s/def ::this-order (s/and (s/keys :req-un [::info ::active ::items])
#(= 3 (count (:items %)))))
;; successful test
(s/explain ::this-order
{:info {:name "Lens"}
:items [1 2 3]
:active false})
;; failing test
(s/explain ::this-order
{:info {}
:items [1 2 3]
:active false})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment