Rspec - match for one of the options

I have a method that returns a random value from a predefined array (namely: [ 'value1', 'value2'] ). How to check this with rspec?

I would like to do something like:

 expect(FooClass.new.value).to be_in ['value1', 'value2'] 

How to do it? Thanks.

+5
source share
1 answer

Use this

 expect(['value1', 'value2']).to include(FooClass.new.value) 

Or a simple logical match

 expect(['value1', 'value2'].include? FooClass.new.value).to be true 
+6
source

Source: https://habr.com/ru/post/1205665/


All Articles