[rspec-users] Checking for Range
Sam Aaron
sam.maillists at googlemail.com
Sun May 27 15:41:33 EDT 2007
On 27 May 2007, at 8.31 pm, Andrew WC Brown wrote:
>
> I thought this would work:
> person.password.length.should == (5..40)
>
I think that in this case, you want to use the === operator when
comparing a number with a range. Instead of trying to see if both of
the objects (the number and the range) are the same, the === operator
checks to see if the number is within the range.
Also, make sure you surround your range with parenthesis (which you
are already doing), and put the range on the left hand side of the
=== operator for it to work. Have a look at this quick irb session
for an example of what I mean:
>> (10..50) == 15
=> false
>> (10..50) === 15
=> true
>> 10..50 === 15
ArgumentError: bad value for range
from (irb):6
>> 15 === 10..50
ArgumentError: bad value for range
from (irb):7
>> 15 === (10..50)
=> false
>>
Hope this helps,
Sam
---
http://sam.aaron.name
More information about the rspec-users
mailing list