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 k开发者_如何学运维now how I include the 'B' in the comparison?
['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.
You can also do:
(x == A || x == B).should be_true
Sample.find(:all).map(&:param).each{ |val| ['A', 'B'].should.include?(value) }
However, this does seem like a bit of an odd test to write.
Assuming you are trying to perform an existence check, I would rewrite your code as follows:
Sample.exists?(:conditions => {:params => %w(A B)}).should_be_true
精彩评论