-1

Working on rspec(2.14.1), rspec-core (2.14.8) & rspec-expectations(2.14.5) versions

Need to expect one of two specific outputs. Tried below statements and got respective errors,

expect(fruit).should be_in('Apple','Mango')

Error

NoMethodError: undefined method `should' for #<RSpec::Expectations::ExpectationTarget:0x007fa63c4336d8>

and

expect(fruit).to eq('Apple').or(eq('Mango'))

and

expect(fruit).to include('Apple').or(eq('Mango'))

Error

NoMethodError: undefined method `or' for #<RSpec::Matchers::BuiltIn::Eq:0x007fa63c431630>

Searched a lot but couldn't find a solution. Is there a way to do it without having to update rspec to 3?

mon23
  • 1

2 Answers2

0

Try this:

expect(fruit).to be_in(['Apple','Mango'])

You are expecting an element (fruit) to be in an array (['Apple', 'Mango'])

WeezHard
  • 1,982
  • 1
  • 16
  • 37
0

You can do...

expect(['Apple', 'Mango'].include?(fruit)).to be true
SteveTurczyn
  • 36,057
  • 6
  • 41
  • 53