proletariat.mocks
Utilties for mocking parts of a program for testing different scenarios. Should only be used in unit tests as we are mucking about under the hood.
multimock
macro
(multimock multi bindings & body)
Creates a mock binding scope allowing a user to replace multimethod functionality for the given Multimethod. Takes a MultiFn (defmulti) and a vector of [dispatch fn] bindings to replace. The body is executed with the updated multimethods and the original multimethod definitions are replaced upon completion. Returns the result of body.
Example:
(defmulti foo (fn [a b] a))
(defmethod foo :bar [a b] [a b])
(foo :bar 1)
;;=> [:bar 1]
(multimock foo
[:bar (fn [a b] [a (inc b)])]
(foo :bar 1))
;;=> [:bar 2]
replace-method
(replace-method multi dispatch f)
Replaces the Multimethod with the given dispatch with the given function
reset-methods
(reset-methods multi m)
Resets all methods associated with the given Multimethod to match what is in the provided map of dispatch->fn.