I am trying to use with-redefs
and reify
to mock methods in clojure. I do not have a clue on where to get started with those. Can anyone please give me an example of mocking a method? The documentation on the internet is of no help for me as I am totally confused with it at this point of time.
Mocking existing methods in Clojure
1.4k Views Asked by srnvs At
2
Let's say you want to spy/mock/stub a function
bar
and test how many times it got called in functionfoo
. A simple example could be:Well, I agree the code above is a bit tedious. You can try out the following macro: (I put invoke history into meta data)
usage:
With a little utilities functions, the macro above could become a powerful tool. The expressiveness of Clojure is so great.