如何“提供”?在米杰的事实中实施?
我正在阅读《Clojure in Action》第 8 章有关 TDD 的内容,并尝试了存根宏。它使用动态绑定机制来存根函数。唉,在 Clojure 1.3 中,不可能对非动态变量使用绑定机制,因此存根宏在大多数情况下不起作用,除非您显式声明指向函数动态的 var。然后我想知道 Midje 中的存根是如何完成的,并试图找到“provided”的来源,但我找不到它。那么问题来了:
“提供”是如何在 Midje 的事实中实现的?有人可以详细解释一下吗?
I was reading Clojure in Action chapter 8 about TDD and experimented with the stubbing macro. It uses the dynamic binding mechanism to stub functions. Alas, in Clojure 1.3 it is not possible to use the binding mechanism for non-dynamic vars, so the stubbing macro doesn't work in most cases, unless you explicitly declare the var which points to a function dynamic. Then I wondered how stubbing is done in Midje and tried to find the source for 'provided', but I couldn't find it. So here it goes:
How is 'provided' implemented in a fact in Midje? Can someone explain this in detail?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Clojure 1.3 提供了一个 with-redefs 宏,甚至可以与尚未声明为动态的变量一起使用:
为了向后兼容,Midje 使用自己的版本,其内容如下:
Clojure 1.3 provides a with-redefs macro that works even with vars that haven't been declared dynamic:
For backward compatibility, Midje uses its own version, whose guts look like this: