问题描述
:focus
您可以使用hash 属性标记示例。例如,
# spec/foo_spec.rb
RSpec.describe Foo do
it 'is never executed' do
raise "never reached"
end
it 'runs this spec', focus: true do
expect(1).to eq(1)
end
end
rspec --tag focus spec/foo_spec.rb
更多信息在GitHub 上。(谁有更好的链接,请指教)
(更新)
RSpec 现在在 relishapp.com 上有很好的记录。有关详细信息,请参阅--tag 选项部分。
从 v2.6
开始,这种标签可以通过包含配置选项来更简单地表示treat_symbols_as_metadata_keys_with_true_values
,它允许您执行以下操作:
describe "Awesome feature", :awesome do
where:awesome
被视为:awesome => true
.
此外,请参阅此答案以了解如何配置 RSpec以自动运行“重点”测试。这对Guard尤其有效。
确保在您的配置中配置了 RSpecspec_helper.rb
以注意focus
:
RSpec.configure do |config|
config.filter_run focus: true
config.run_all_when_everything_filtered = true
end
然后在您的规范中,添加focus: true
为参数:
it 'can do so and so', focus: true do
# This is the only test that will run
end
您还可以通过更改it
为fit
(或使用 排除测试xit
)来集中测试,如下所示:
fit 'can do so and so' do
# This is the only test that will run
end
解决方法
我认为有一种方法可以只运行具有给定标签的测试。有人知道吗?