我有一个rspec测试,看起来像这样:
require 'rspec'
describe 'describe', :mytag do
puts("inside describe")
it 'test', :mytag do
puts 'test'
end
end
如果我指定这样的其他标记,我希望能够跳过整个规格文件(以及describe
中的一部分):
rspec test_spec.rb --tag other
但是代码inisde describe
已执行并输出inside describe
有什么办法可以过滤掉此代码?
我知道我可以将代码更改为以下内容:
require 'rspec'
describe 'describe', :mytag do
before(:all) do
puts("inside describe")
end
it 'test', :mytag do
puts 'test'
end
end
但这需要在许多文件中进行很多更改,因此我正在寻找更简单的解决方案。
答案 0 :(得分:0)
我的最终解决方案不是很好,但是可以有效地完成工作(感谢@noname指出解决方案的方向)
我创建了一个新的rake任务,该任务将过滤具有指定标签的文件,然后创建子进程以仅运行经过过滤的规范(就像rspec --fail-fast
一样,在第一次失败时失败(根据需要)
像这样
files_with_tag = `grep -Ril spec/ -e ':mytag'`.split("\n")
files_with_tag.each do |current_file|
result = `rspec #{current_file} --tag mytag`
puts(result)
exit unless result.include?('0 failures')
end