-
-
Save telekid/01b0aed73511167c337794bc286908cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: @colinkahn on Clojurians slack recommended using :replace instead of :stub.