Rspec标签和过滤器 - 过滤器的多个值?
问题描述:
我有一个测试套件,可以运行多个版本的软件应用程序。我希望能够标记那些根据不同版本而变化的测试,以便我设置的过滤器只运行这个特定版本的测试。Rspec标签和过滤器 - 过滤器的多个值?
我在寻找类似:
describe "the magic page", :version=>["all-magic", "some_magic"]
it "exists!"
end
describe "the magic page", :version=>["no-magic"]
it "does not exist!"
end
Rspec.configure do |config|
this_version= some_version_parameter_passed_in || "no_magic"
config.filter_run :version includes this_version
end
显然,这是不行的,但它应该给你什么,我试图完成一个想法。
答
你可以用Rspec来做到这一点。看看在docs,并尝试这样的事:
describe "the magic page", :all-magic => true, :some-magic => true
it "exists!"
end
describe "the magic page", :no-magic => true
it "does not exist!"
end
然后与魔法标记运行测试,你可以使用命令:
rspec --tag magic
,也可以编辑您的.rspec
:
--tag magic
这是否适合您?
答
您可以使用lambda表达式在你的过滤器是这样的:
config.filter_run_including :foo => lambda {|v| v == 'bar'}
所以你可以做这样的事情
config.filter_run_including :version => lambda {|v| v.include? current_version}
或与正确的唯一运行测试:版本(我认为这是什么你正在寻找),
config.filter_run_excluding :version => lambda {|v| !v.include? current_version}
+0
适用于我,当我想运行一个关键的多个值的情况下,谢谢 – user2256777
好的,这在技术上回答了这个问题,所以你明白了。但它主要是为了说明这个问题不足以解决我的问题。 ;)我会提出一个新的,稍微宽泛的问题,但是要感谢出发点。 – GlyphGryph
好吧,听起来不错。 –