[rspec-users] Checking for Range

Andrew WC Brown omen.king at gmail.com
Sun May 27 16:17:35 EDT 2007


  it "should require a password within the range of 5..40 characters" do
    person = create(:last_name => "ruby_tuesday")
    person.password.should_not be_nil
    (5..40) === person.password.length.should
  end

Its true, it really works, tell all your friends!

On 5/27/07, Sam Aaron <sam.maillists at googlemail.com> wrote:
>
>
> 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
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070527/188c97e6/attachment.html 


More information about the rspec-users mailing list