Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rspec-如何创建带有标记的宏?_Ruby On Rails_Rspec_Rspec2_Rspec3 - Fatal编程技术网

Ruby on rails 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宏

例如,使用

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中的规范

是,我知道
挂起
。但我想动态调用一组测试。所以这行不通。是的,我知道
挂起了
。但我想动态调用一组测试。所以这行不通。