RSpec 中有没有办法让 'not' 的优先级高于所有匹配器?
Is there a way in RSpec to give 'not' higher precedence than the all matcher?
RSpec 3 提供了all matcher。例如,
expect(['Tom', 'Tony', 'Rosa']).to all( include("o") )
你也可以
expect(['Tom', 'Tony', 'Rosa']).to_not all( include("o") )
但是"to all not"怎么表达呢?
根据文档和快速阅读代码,似乎没有内置 all_not
匹配器,因此必须遍历数组才能获得结果,如下所示:
['Tom', 'Tony', 'Rosa'].each { |name| expect(name).to_not contain('o') }
您可以查看内置匹配器,包括 all
在 https://github.com/rspec/rspec-expectations/blob/9ff22694fa88cb0b0e794b6f99f3cfacfa909bf4/lib/rspec/matchers/built_in/all.rb
定义要用来测试列表中每个元素的匹配器的否定版本,例如,
RSpec::Matchers.define_negated_matcher :exclude, :include
并像
一样使用它
expect(%w(Tom Tony Rosa)).to all(exclude('o'))
RSpec 3 提供了all matcher。例如,
expect(['Tom', 'Tony', 'Rosa']).to all( include("o") )
你也可以
expect(['Tom', 'Tony', 'Rosa']).to_not all( include("o") )
但是"to all not"怎么表达呢?
根据文档和快速阅读代码,似乎没有内置 all_not
匹配器,因此必须遍历数组才能获得结果,如下所示:
['Tom', 'Tony', 'Rosa'].each { |name| expect(name).to_not contain('o') }
您可以查看内置匹配器,包括 all
在 https://github.com/rspec/rspec-expectations/blob/9ff22694fa88cb0b0e794b6f99f3cfacfa909bf4/lib/rspec/matchers/built_in/all.rb
定义要用来测试列表中每个元素的匹配器的否定版本,例如,
RSpec::Matchers.define_negated_matcher :exclude, :include
并像
一样使用它expect(%w(Tom Tony Rosa)).to all(exclude('o'))