我是新来的Clojure所以请原谅任何明显的错误的宏操作。我试图测试一些使用redis-clojure库的Clojure数据访问代码。虽然我的集成测试当然会测试整个堆栈,但我不希望我的单元测试依赖于连接到redis服务器实例。用Midje嘲弄实际的Redis命令似乎是相对直接的,但是连接宏更难处理。
建议需要
似乎什么不能做或发现通过Midje文档嘲讽Redis的连接或重新定义宏的方式。从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#)]
[email protected]))))
(original code in context here)
我似乎没有能够重新定义宏在我的测试代码和功能包宏没有按因为我仍然需要身体被执行来产生我的结果,所以我不会再向前走。我最想做的是执行传递给连接宏的主体,并丢弃宏的其余部分。有任何想法吗?
经过这个问题,我发现https:// github。com/ptaoussanis/carmine/issues/16,然后决定对我的单元测试命中本地redis实例是完全正确的 –