-
-
Save glenjamin/7edfefcbf1eaa02d6a58 to your computer and use it in GitHub Desktop.
Possible approach to stub spies
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
(def stubs "Keep a track of all calls to stubs" (atom {})) | |
(defmacro stub | |
"Replace function with a canned version that records its calls" | |
[func canned & body] | |
`(with-redefs [~func (fn stub[& args#] | |
(swap! (get @stubs ~func) conj args#) | |
~canned)] | |
(swap! stubs assoc ~func (atom [])) | |
(try | |
~@body | |
(finally (swap! stubs dissoc ~func))))) | |
(defn stub-calls | |
"Fetch stub calls for function" | |
[func] @(get @stubs func)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment