[rspec-users] Checking for Range

David Chelimsky dchelimsky at gmail.com
Sun May 27 15:39:39 EDT 2007


On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote:
> Well I get error as such:
>
> 1)
> NoMethodError in 'Person should require a password within the range of 5..40
> characters'
> undefined method `range' for "ruby_tuesday":String
> ./spec/models/person_spec.rb:43:
>
> and I have a feeling that they're right when they say string doesn't have a
> range method.
>
> I thought this would work:
> person.password.length.should == (5..40)
>
> but doesn't look so
>
>  1)
> ArgumentError in 'Person should require a password within the range of 5..40
> characters'
> wrong number of arguments (1 for 2)
> ./spec/models/person_spec.rb:43:in `initialize'
> ./spec/models/person_spec.rb:43:in `new'
> ./spec/models/person_spec.rb:43:

OK. I should have asked for the backtrace first. It's generally a good
idea to include backtraces rather than just saying "it doesn't work".

"Person should require a password within the range of 5..40" suggests
to me that you should have several examples:

Person should require password length between 5 and 40
- should not accept a password of length 4
- should accept a password of length 5
- should accept a password of length 40
- should not accept a password of length 41

Make sense?


>
>
>
>
> On 5/27/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> >
> > On 5/27/07, David Chelimsky <dchelimsky at gmail.com > wrote:
> > > On 5/27/07, Andrew WC Brown <omen.king at gmail.com> wrote:
> > > > how would you check for a range using rspec?
> > > >
> > > > person.password.range.should == Range.new(5..40) <- this doesn't work
> > >
> > > The correct ruby syntax is Range.new(5, 40). So this should work:
> > >
> > > person.password.range.should == Range.new(5, 40)
> >
> > OR ....
> >
> > person.password.range.should == (5..40) #shortcut for Range.new(5, 40)
> >
> >
> > >
> > > Cheers,
> > > David
> > >
> > _______________________________________________
> > 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
>


More information about the rspec-users mailing list