Background
I'm new to Clojure so please forgive any glaring errors. I am trying to test some Clojure data access code that uses the redis-clojure library. Whilst my integration tests will, of course, test the full stack I do not want my unit tests to be reliant upon connecting to a redis server instance. Mocking the actual Redis commands with Midje appears to be relatively straight-forward however, the connection macro is more difficult to deal with.
Suggestions needed
What can't seem to do or find via the Midje documentation is way of mocking the redis connection or redefining the macro. The relevant top level connection macro from core.clj is:
(defmacro with-server
"Evaluates body in the context of a connection to Redis server
specified by server-spec.
server-spec is a map with any of the following keys:
:host (\"127.0.0.1\")
:port (6379)
:db (0)
:timeout (5000)
:password (nil)"
([server-spec & body]
`(with-connection connection# *pool* ~server-spec
(binding [redis.vars/*channel* (make-direct-channel connection#)]
~@body))))
(original code in context here)
I don't appear to be able to redefine the macro in my test code and wrapping the macro in a function doesn't get me any further forwards as I still need the body to be executed to produce my result. What I'd ideally like to do is execute the body passed into the connection macro and discard the rest of the macro. Any ideas?