使用rspec(2.14.1),rspec-core(2.14.8)& rspec-expectations(2.14.5)版本
需要预期两种特定输出中的一种。试过以下陈述并得到各自的错误,
expect(fruit).should be_in('Apple','Mango')
错误
NoMethodError: undefined method `should' for #<RSpec::Expectations::ExpectationTarget:0x007fa63c4336d8>
和
expect(fruit).to eq('Apple').or(eq('Mango'))
和
expect(fruit).to include('Apple').or(eq('Mango'))
错误
NoMethodError: undefined method `or' for #<RSpec::Matchers::BuiltIn::Eq:0x007fa63c431630>
搜索了很多但找不到解决方案。有没有办法做到这一点,而无需将rspec更新为3?
答案 0 :(得分:0)
试试这个:
expect(fruit).to be_in(['Apple','Mango'])
您希望元素(fruit
)位于数组中(['Apple', 'Mango']
)
答案 1 :(得分:0)
你可以......
expect(['Apple', 'Mango'].include?(fruit)).to be true