Jeff Jeff - 1 year ago 141
Ruby Question

How do you compare multiple RHS values in RSPec?

I'm new to RSpec, and I'm trying to run "should == A || B", but it's ignoring the 'B' and is only comparing with 'A' (and thus failing when val is 'B'):

Sample.find(:all).map(&:param).each{|val| val.should == 'A'||'B'}

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

Answer Source
['A', 'B'].should include(val)

That might get your spec passing, but is it what you want to test? That the return value is a member of a set? If so, then perhaps this is a good solution.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download