zet*_*tic 177
找到文档并不容易,但您可以使用哈希标记示例.例如.
# 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的更多信息.(任何有更好链接的人,请指教)
(更新)
RSpec现在在这里有很好的记录.有关详细信息,请参阅--tag选项部分.
从v2.6开始,通过包含配置选项可以更简单地表达这种标记treat_symbols_as_metadata_keys_with_true_values,这允许您执行以下操作:
describe "Awesome feature", :awesome do
在哪里:awesome被视为好像:awesome => true.
另请参阅此答案,了解如何配置RSpec以自动运行"聚焦"测试.这与Guard特别有效.
Jan*_*rik 104
您可以使用--example(或-e)选项运行包含特定字符串的所有测试:
rspec spec/models/user_spec.rb -e "User is admin"
我最常用的那个.
Tom*_*pin 81
在你的spec_helper.rb:
RSpec.configure do |config|
    config.filter_run focus: true
    config.run_all_when_everything_filtered = true
end
然后根据您的规格:
it 'can do so and so', focus: true do
    # This is the only test that will run
end
您也可以使用'fit'进行测试或使用'xit'排除测试,如下所示:
fit 'can do so and so' do
    # This is the only test that will run
end
Jon*_*son 47
您还可以使用冒号将多个行号串起来:
$ rspec ./spec/models/company_spec.rb:81:82:83:103
输出:
Run options: include {:locations=>{"./spec/models/company_spec.rb"=>[81, 82, 83, 103]}}
Jos*_*eim 25
作为RSpec的2.4(我猜),你可以在前面加上一个f或x至it,specify,describe和context:
fit 'run only this example' do ... end
xit 'do not run this example' do ... end
http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#fit-class_method http://rdoc.info/github/rspec/rspec-core/RSpec/Core/ExampleGroup#xit-class_method
一定有config.filter_run focus: true和config.run_all_when_everything_filtered = true你的spec_helper.rb.
在较新版本的 RSpec 中,配置支持更加容易fit:
# spec_helper.rb
# PREFERRED
RSpec.configure do |c|
  c.filter_run_when_matching :focus
end
# DEPRECATED
RSpec.configure do |c|
  c.filter_run focus: true
  c.run_all_when_everything_filtered = true
end
看:
https://relishapp.com/rspec/rspec-core/docs/filtering/filter-run-when-matching
https://relishapp.com/rspec/rspec-core/v/3-7/docs/configuration/run-all-when-everything-filtered
focus: true您也可以运行默认情况下具有的规范
规范/spec_helper.rb
RSpec.configure do |c|
  c.filter_run focus: true
  c.run_all_when_everything_filtered = true
end
然后只需运行
$ rspec
并且只会运行重点测试
然后当您删除focus: true所有测试时,我们将再次运行
更多信息:https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/filtering/inclusion-filters