如何在 shoulda 宏中创建上下文
用较小的代码示例再次问这个问题:
# this is a dummy shoulda macro that creates a context
def self.macro_context
context "macro" do
yield
end
end
# i am expecting this test to fail within the macro context
context "some context" do
macro_context do
should "test" do
fail
end
end
end
所以我期望看到的是:
1) Error:
test: some context macro context should test. (TestClassName)
但我只得到这个:
所以我期望看到的是:
1) Error:
test: some context should test. (TestClassName)
知道我做错了什么吗?
Asking this question again with smaller code sample:
# this is a dummy shoulda macro that creates a context
def self.macro_context
context "macro" do
yield
end
end
# i am expecting this test to fail within the macro context
context "some context" do
macro_context do
should "test" do
fail
end
end
end
So what I would expect is to see:
1) Error:
test: some context macro context should test. (TestClassName)
But I am getting only this:
So what I would expect is to see:
1) Error:
test: some context should test. (TestClassName)
Any idea what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的代码中有类似的东西。我在
test/shoulda_macros/whatever_file.rb
中这样做了I have something similar in my code. And I did it like this into
test/shoulda_macros/whatever_file.rb
感谢弗朗西斯科提供的代码,要解决此问题,您不能只在新上下文中生成块,您必须使用 shoulda 的 merge_block 方法。那么它应该看起来像这样:
Thanks Francisco for the code, to fix this you cannot just yield the block inside of your new context, you have to use shoulda's merge_block method. It then should look like this: