Skip to content

Instantly share code, notes, and snippets.

@telekid telekid/fdef-:fn.clj Secret
Created Feb 12, 2020

What would you like to do?
(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
;; 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)

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.