如何在 Rspec 中仅运行特定测试? [英] How do I run only specific tests in Rspec?
问题描述
我认为有一种方法可以只运行带有给定标签的测试.有人知道吗?
I think there's a way to run only tests with a given label. Anybody know?
推荐答案
查找文档并不容易,但您可以使用哈希标记示例.例如.
It isn't easy to find the documentation, but you can tag examples with a hash. Eg.
# spec/my_spec.rb
describe SomeContext do
it "won't run this" do
raise "never reached"
end
it "will run this", :focus => true do
1.should == 1
end
end
$ rspec --tag focus spec/my_spec.rb
有关 GitHub 的更多信息.(谁有更好的链接,请指教)
More info on GitHub. (anyone with a better link, please advise)
(更新)
RSpec 现在在这里有很好的记录.请参阅 --tag 选项 部分了解详情.
RSpec is now superbly documented here. See the --tag option section for details.
从 v2.6 开始,可以通过包含配置选项 treat_symbols_as_metadata_keys_with_true_values
来更简单地表达这种标记,它允许您执行以下操作:
As of v2.6 this kind of tag can be expressed even more simply by including the configuration option treat_symbols_as_metadata_keys_with_true_values
, which allows you to do:
describe "Awesome feature", :awesome do
其中 :awesome
被视为 :awesome =>真的
.
另请参阅此答案,了解如何配置 RSpec 以自动运行聚焦"测试.这对 Guard 尤其有效.
Also see this answer for how to configure RSpec to automatically run 'focused' tests. This works especially well with Guard.
这篇关于如何在 Rspec 中仅运行特定测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!