How do you compare multiple RHS values ​​in RSPec?

I am new to RSpec and I am trying to run “must == A || B”, but it ignores “B” and only compares with “A” (and thus fails when val is “B '):
Sample.find(:all).map(&:param).each{|val| val.should == 'A'||'B'}

Does anyone know how I include "B" in the comparison?

+3
source share
4 answers
['A', 'B'].should include(val)

This may lead to passing the spec, but is that what you want to check? What is the return value a member of the set? If so, then perhaps this is a good solution.

+4
source

You can also do:

(x == A || x == B).should be_true
+2
source
Sample.find(:all).map(&:param).each{ |val| ['A', 'B'].should.include?(value) }

.

0

, , :

Sample.exists?(:conditions => {:params => %w(A B)}).should_be_true
0

All Articles