Zack Xu Zack Xu - 1 year ago 64
Ruby Question

Is there a way in RSpec to give 'not' higher precedence than the all matcher?

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"?

Answer Source

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'))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download