Background
I am new to Clojure, so please forgive any blatant mistakes. I am trying to verify a Clojure data access code that uses the redis-clojure library . Although my integration tests, of course, will check the full stack, I do not want my unit tests to depend on the connection to the redis server instance. The offset of the actual Redis commands from Midje seems relatively straightforward, however the join macro is harder to handle.
Required Suggestions
What the documentation cannot seem to find or find through Midje is to mock the redis connection or redefine the macro. The corresponding top-level connection macro from core.clj :
(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))))
( source code in context here )
I cannot redefine the macro in my test code, and moving the macro to a function does not give me further forwards, since I still need a body that will be executed to get my result. What I ideally would like to do is execute the body passed to the join macro and discard the rest of the macro. Any ideas?
source
share