Skip to content

Instantly share code, notes, and snippets.

@stuarthalloway
Created October 13, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuarthalloway/d083cd4bbbe6baabbdf3826180b655fa to your computer and use it in GitHub Desktop.
Save stuarthalloway/d083cd4bbbe6baabbdf3826180b655fa to your computer and use it in GitHub Desktop.
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