How about:
expect(foo.bar & ['A', 'B']).to have(1).item
This solution takes the array, intersects it with the possible values, and makes sure that only one element (either 'A'
or 'B'
) is left.
@steenslag's answer fails because when rspec expectations fail, they stop the test, so "two falses don't make a true"...
If you want to use the old should
syntax, it would look like this:
(foo.bar & ['A', 'B']).should have(1).item