Ruby on rails Rspec-如何创建带有标记的宏?
有没有办法有条件地运行Rspec宏 例如,使用Ruby on rails Rspec-如何创建带有标记的宏?,ruby-on-rails,rspec,rspec2,rspec3,Ruby On Rails,Rspec,Rspec2,Rspec3,有没有办法有条件地运行Rspec宏 例如,使用 RSpec.configure do |c| c.filter_run_excluding :broken => true end ## This should get skipped it_should_validate_with_macro :some_param, :broken => true 注意:这是动态调用测试组。所以,pending这类解决方案不是我想要的 describe "an example" do i
RSpec.configure do |c|
c.filter_run_excluding :broken => true
end
## This should get skipped
it_should_validate_with_macro :some_param, :broken => true
注意:这是动态调用测试组。所以,pending
这类解决方案不是我想要的
describe "an example" do
it "is implemented but waiting" do
pending("something else getting finished")
this_should_not_get_executed
end
end
从
从中,您可以在相同的过程中运行规范,还可以执行以下操作 但一个简单的例子可能对您有用,就是创建一个ruby脚本:
require 'rspec/core'
RSpec.configuration.add_setting(:some_setting)
RSpec.configuration.some_setting = false
RSpec::Core::Runner.run(['spec/models/bar.rb'])
RSpec.clear_examples
if RSpec.configuration.some_setting
RSpec::Core::Runner.run(['spec/models/foo.rb'])
end
然后,在将修改设置的rspec脚本中:
RSpec.describe 'bar' do
it 'bar' do
RSpec.configuration.some_setting = true
end
end
这将有条件地在
foo.rb
中运行规范。您可以在相同的过程中运行规范,还可以执行以下操作
但一个简单的例子可能对您有用,就是创建一个ruby脚本:
require 'rspec/core'
RSpec.configuration.add_setting(:some_setting)
RSpec.configuration.some_setting = false
RSpec::Core::Runner.run(['spec/models/bar.rb'])
RSpec.clear_examples
if RSpec.configuration.some_setting
RSpec::Core::Runner.run(['spec/models/foo.rb'])
end
然后,在将修改设置的rspec脚本中:
RSpec.describe 'bar' do
it 'bar' do
RSpec.configuration.some_setting = true
end
end
这将有条件地运行
foo.rb中的规范
是,我知道挂起
。但我想动态调用一组测试。所以这行不通。是的,我知道挂起了。但我想动态调用一组测试。所以这行不通。