Reputation: 11892
RSpec 3 provids the all matcher. For example,
expect(['Tom', 'Tony', 'Rosa']).to all( include("o") )
You can also have
expect(['Tom', 'Tony', 'Rosa']).to_not all( include("o") )
But how do you express "to all not"?
Upvotes: 1
Views: 114
Reputation: 37647
Define a negated version of the matcher with which you want to test each element of the list, for example,
RSpec::Matchers.define_negated_matcher :exclude, :include
and use it like
expect(%w(Tom Tony Rosa)).to all(exclude('o'))
Upvotes: 3
Reputation: 29419
Per the documentation and a quick perusal of the code, there appears to be no built in all_not
matcher, so one would have to iterate over the array to achieve the result, as follows:
['Tom', 'Tony', 'Rosa'].each { |name| expect(name).to_not contain('o') }
You can view the built-in matchers, including all
at https://github.com/rspec/rspec-expectations/blob/9ff22694fa88cb0b0e794b6f99f3cfacfa909bf4/lib/rspec/matchers/built_in/all.rb
Upvotes: 0