Rspec: Should be (this or that)

后端 未结 6 1198
無奈伤痛
無奈伤痛 2020-12-16 09:38

What would be the best way to write the rspec in a situation where either of two (or more) outcomes are acceptable?

Here\'s an example of what I want to do. This is

6条回答
  •  生来不讨喜
    2020-12-16 10:10

    ActiveSupport provides Object#in? method. You can combine it with RSpec and simply use the following:

    flip_coin.should be_in(["heads", "tails"])
    

    Or with new Rspec 3 syntax:

    expect(flip_coin).to be_in(["heads", "tails"])
    

提交回复
热议问题