[rspec-users] Checking for Range

Andrew WC Brown omen.king at gmail.com
Sun May 27 18:34:23 EDT 2007


I'm testing the validation
validates_length_of :password, :within => 5..40

In this case I should be receiving a failure but I'm not :(

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

I'm an amature tester, would you tell me how I should verify?
I haven't fully grasped setting testing goals

On 5/27/07, David Chelimsky <dchelimsky at gmail.com> wrote:
>
> On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote:
> >   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!
>
> How does that verify that a person will reject a password length of 4 or
> 41?
>
> >
> >
> > 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
> > >
> >
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
> _______________________________________________
> 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/ed416647/attachment.html 


More information about the rspec-users mailing list