Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.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 如何制作示例的复杂过滤器_Ruby On Rails_Ruby_Testing_Bdd_Rspec2 - Fatal编程技术网

Ruby on rails 如何制作示例的复杂过滤器

Ruby on rails 如何制作示例的复杂过滤器,ruby-on-rails,ruby,testing,bdd,rspec2,Ruby On Rails,Ruby,Testing,Bdd,Rspec2,我试着做一些复杂的过滤器的例子。 我有以下代码: require 'rspec' RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :foo => true end describe 'Filtering' do tested_text = 'foooobar' [:foo, :bar].each do

我试着做一些复杂的过滤器的例子。 我有以下代码:

require 'rspec'

RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.filter_run :foo => true
end

describe 'Filtering' do

  tested_text = 'foooobar'

  [:foo, :bar].each do |location|
    [:first, :second].each do |current|
      describe 'aaa ' + location.to_s, location => true do

        before :all, location => true do
          puts location
        end

        describe 'bbbb '+ current.to_s, current => true do

          before :all, current => true do
            puts current
          end

          it 'case 1 ' do
            puts 'case 1 ' + tested_text.to_s
          end
        end
      end
    end
  end

  after :each do
    puts 'refresh doc'
  end
end
当我运行“rspec”时,我有一些输出

foo
first
case 1 foooobar
refresh doc
foo
second
case 1 foooobar
refresh doc

2 examples, 0 failures, 2 passed

Finished in 0.006087512 seconds
但如果我只想运行一个示例并将这一行添加到Rspec.configure

config.filter_run :first => true
我想得到

foo
first
case 1 foooobar
refresh doc
但当我有一些意想不到的输出

foo
first
case 1 foooobar
refresh doc
foo
second
case 1 foooobar
refresh doc
bar
first
case 1 foooobar
refresh doc

3 examples, 0 failures, 3 passed

Finished in 0.011501239 seconds

enybody知道如何使其正常工作吗?谢谢。

当您指定两个
filter\u run
调用时,rspec似乎将它们视为条件a或条件b

您可以将这两个条件合并为一个条件:

RSpec.configure do|config|
config.treat_symbols_作为_元数据_键_,值为true
config.filter_run:foo=>lambda{v,m | m[:foo]==true和m[:first]==true}
结束
#或者(如果您有许多条件需要检查,可能会更容易)
RSpec.configure do | config|
config.treat_symbols_作为_元数据_键_,值为true
config.filter_run:foo=>lambda{v,m{foo,:first]。所有?{k}m[k]}
结束

请看一下的文档。

非常感谢。我尝试用lambda将两个条件合并为一个,但我是这样做的:config.filter\u run:condition=>lambda{m | m[:foo]==true和m[:first]==true}