RSpec Tags提供了一种在规范文件中运行特定测试的简便方法。假设您只想运行指定测试方法,则可以使用Tags标签实现。
describe "How to run specific Examples with Tags" do it 'is a slow test', :slow=> true do sleep 10 puts 'This test is slow!' end it 'is a fast test', :fast=> true do puts 'This test is fast!' end end
现在,将上面的代码保存在一个名为tag_spec.rb的新文件中。在命令行中,运行以下命令: rspec --tag slow tag_spec.rb
您将看到此输出-
This test is slow! . Finished in 10 seconds (files took 0.11601 seconds to load) 1 example, 0 failures
然后,运行以下命令:rspec --tag fast tag_spec.rb
Run options: include {:fast=>true} This test is fast! . Finished in 0.001 seconds (files took 0.11201 seconds to load) 1 example, 0 failures
如您所见,RSpec标签使子集测试非常容易!
参考链接
https://www.learnfk.com/rspec/rspec-tags.html
标签:slow,Tags,seconds,无涯,fast,tag,RSpec,test From: https://blog.51cto.com/u_14033984/8471132