(defn make-mock
"creates a vector containing the following information for the named function:
1. dependent function replacement - verifies signature, calls arg checker,
increases count, returns return value.
2. an atom containing the invocation count
3. the invocation count checker function
4. a symbol of the name of the function being replaced."
[fn-name expectation-hash]
(assert-args make-mock
(map? expectation-hash) "a map of expectations")
(let [arg-checker (or (expectation-hash :has-args) (fn [& args] true))
count-atom (atom 0)
ret-fn (or
(expectation-hash :calls)
(fn [& args] (expectation-hash :returns)))]
[(fn [& args]
(has-matching-signature? fn-name args)
(apply arg-checker fn-name args)
(swap! count-atom inc)
(apply ret-fn args))
count-atom
(or (expectation-hash :times) (fn [fn-name v] true))
fn-name]))
Vars in
circumspec.contrib-mocking/make-mock:
defn
let
map?
Used in 0 other vars
Comments top
No comments for make-mock. Log in to add a comment.