-1

处理 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?

4

2 回答 2

0

你可以做...

expect(['Apple', 'Mango'].include?(fruit)).to be true
于 2016-01-16T22:32:05.857 回答
0

尝试这个:

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

您期望元素 ( fruit) 在数组 ( ['Apple', 'Mango'])中

于 2016-01-16T22:25:31.523 回答