如何解决如何在 Rspec 中仅运行特定测试?
: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
解决方法
我认为有一种方法可以只运行具有给定标签的测试。有人知道吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。