Skip to content

Instantly share code, notes, and snippets.

@telekid
Created February 12, 2020 23:18
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 telekid/01b0aed73511167c337794bc286908cf to your computer and use it in GitHub Desktop.
Save telekid/01b0aed73511167c337794bc286908cf to your computer and use it in GitHub Desktop.
(require '[clojure.spec.alpha :as s]
'[clojure.spec.test.alpha :as s-test])
(s/fdef inner
:args (s/cat :i int?)
:ret int?)
(defn inner [i] i)
(s/def ::result-1 int?)
(s/def ::result-2 int?)
(s/fdef outer
:args (s/cat :i int?)
:ret (s/keys :req [::result-1
::result-2])
;; This fn will fail because the values generated by the calls to
;; inner will differ.
:fn #(= (-> % :ret ::result-1)
(-> % :ret ::result-2)))
(defn outer [i]
(let [result-1 (inner i)
result-2 (inner i)]
{::result-1 result-1
::result-2 result-2}))
(s-test/instrument `inner {:stub #{`inner}})
(s-test/check `outer)
@telekid
Copy link
Author

telekid commented Feb 13, 2020

Update: @colinkahn on Clojurians slack recommended using :replace instead of :stub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment