用于没有文字描述的测试的 Rspec 标签?
非常简单的问题,但我在文档中找不到答案。 如何向缺少文本描述的特定 Rspec 示例添加标签?例如,如果您使用相当常见的“:focus”标签来选择要运行的测试(尽管这不是我需要标签的唯一用途),那么通常您会写:
specify "the value should be 2", :focus => true do
@value.should be(2)
end
但是,这并不罕见对于简单的测试以避免冗余,让测试本身进行对话并省略“值应该是 2”元素,给您类似的内容:
context "the value" do
subject{@value}
it {should be(2)}
it {should_not be(3)
end
但是,我不知道如何向此类测试添加标签。这可能吗?像这样的东西:
it :focus {should have_content("Oh yeah")}
Pretty simple question, but I can't find an answer in the docs.
How can I add tags to specific Rspec examples that lack textual descriptions? For example, if you are using the fairly common ":focus" tag to select the tests you want to run (though that's not the only thing I need the tags for), you would, normally, write:
specify "the value should be 2", :focus => true do
@value.should be(2)
end
However, it is not uncommon for simple tests to avoid redundancy to let the test itself do the talking and leave out the "the value should be 2" element, giving you something like:
context "the value" do
subject{@value}
it {should be(2)}
it {should_not be(3)
end
However, I can't figure out how to add tags to that sort of test. Is this possible? Something like:
it :focus {should have_content("Oh yeah")}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很接近,但 Ruby 不会解析它:focus => true { ... }。试试这个:
it(:focus => true) { should do_something }
You were close, but Ruby won't parse
it :focus => true { ... }
. Try this:it(:focus => true) { should do_something }
是的,这是可能的。试试吧!在执行
之前,您可能需要先调用
。subject
,{should have_content('Oh Yeah')}Yes, this is possible. Try it! You may need to call
subject
before you doit {should have_content('Oh yeah')}
.