Midje,如果没有按我的预期工作
我编写了以下 Midje 测试:
(fact (followers-minus-friends ...name...) => ["Dude"]
(provided (idset show-followers ...name...) => #{1 2 3}
(idset show-friends ...name...) => #{1 2}
(userinfos #{3}) => [{:screen_name "Dude"}]))
测试以下函数(在不同的命名空间中):
(defn followers-minus-friends [screenname]
(let [difference-ids (difference (idset show-followers screenname)
(idset show-friends screenname))
userinfos (userinfos difference-ids)]
(map :screen_name userinfos)))
该测试可能看起来毫无用处,但我只是想习惯 Midje。不知何故,函数 idset 就被执行了,我想通过在提供的子句中提供返回值来阻止这种情况。对此有何解释?
编辑:我已将项目上传到 Github,以防您想尝试重现上述情况:https://github.com/Borkdude/twitter-utils
I have written the following Midje test:
(fact (followers-minus-friends ...name...) => ["Dude"]
(provided (idset show-followers ...name...) => #{1 2 3}
(idset show-friends ...name...) => #{1 2}
(userinfos #{3}) => [{:screen_name "Dude"}]))
to test the following function (in a different namespace):
(defn followers-minus-friends [screenname]
(let [difference-ids (difference (idset show-followers screenname)
(idset show-friends screenname))
userinfos (userinfos difference-ids)]
(map :screen_name userinfos)))
The test may seem pretty useless, but I'm just trying to get accustomed to Midje. Somehow, the function idset just gets executed, which I wanted to prevent by providing a return value in the provided-clause. What could be an explanation for this?
EDIT: I have uploaded the project to Github here, in case you want to try to reproduce the above situation: https://github.com/Borkdude/twitter-utils
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于函数 idset 在源命名空间中是私有的。在测试文件中,您将其保留在测试命名空间中。现在,您有两个指向同一个函数的不同变量:
在
provided
中,您将覆盖第二个变量以指向先决条件函数。然而,函数followers-minus-friends
仍然引用第一个变量。这没有被覆盖,所以你得到了原始的函数。围绕
private
声明进行路由的常见习惯用法是使用完整的 var 名称,如上所述。所以你会期望这能起作用:但事实并非如此。我认为这是 Midje 的一个错误。至少,我暂时看不出支持这样做会带来什么危害。我会开一张票。
按照目前的情况,您需要将
idset
公开。The problem is that the function
idset
is private in your source namespace. In the test file, you intern it in the test namespace. You now have two different vars that point to the same function:In the
provided
, you are overriding the second var to point to a prerequisite function. However, the functionfollowers-minus-friends
still refers to the first var. That is not overridden, so you get the original function.A common idiom for routing around
private
declarations is to use the full var name, as above. So you'd expect this to work:It doesn't, though. I consider that a bug in Midje. At least, I can't offhand see what harm supporting that would do. I'll file a ticket.
As it stands, you need to make
idset
public.