That actaully makes alot of sense now.<br>Does this have to do with something State vs Behaviour verfication?<br>I've been reading alot about stubs and mocks.<br>It took a long which to comprehend.<br><br><div><span class="gmail_quote">
On 5/28/07, <b class="gmail_sendername">David Chelimsky</b> <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 5/27/07, Andrew WC Brown <<a href="mailto:omen.king@gmail.com">omen.king@gmail.com</a>> wrote:<br>> I'm testing the validation<br>> validates_length_of :password, :within => 5..40<br>><br>> In this case I should be receiving a failure but I'm not :(
<br>><br>> it "should require a password within the range of 5..40 characters" do<br>> person = create(:password => 'a')<br>> person.password.should_not be_nil<br>> person.should
validate_length_of(:password, 5..40)<br>> end<br>><br>> I'm an amature tester, would you tell me how I should verify?<br>> I haven't fully grasped setting testing goals<br><br>The behaviour you're trying to describe is that the User should
<br>require that passwords bear certain qualities - in this case a length<br>between 5 and 40. So you need to ask yourself how the User should<br>behave when this requirement is violated, and then specify that it<br>behaves that way.
<br><br>Here's how I might handle this:<br><br>describe User do<br> it "should reject a password of length 4" do<br> User.create(:password => "1234").should have(1).error_on(:password)<br> end
<br> it "should accept a password of length 5" do<br> User.create(:password => "12345").should have(0).errors_on(:password)<br> end<br> it "should accept a password of length 40" do<br>
User.create(<br> :password => "1234567890123456789012345678901234567890"<br> ).should have(0).errors_on(:password)<br> end<br> it "should reject a password of length 41" do<br> User.create
(<br> :password => "12345678901234567890123456789012345678901"<br> ).should have(1).error_on(:password)<br> end<br>end<br><br>And possibly add something about the specific error message in one of the cases.
<br><br>That make sense?<br><br>><br>> On 5/27/07, David Chelimsky <<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>> wrote:<br>> ><br>> > On 5/27/07, Andrew WC Brown <<a href="mailto:omen.king@gmail.com">
omen.king@gmail.com</a> > wrote:<br>> > > it "should require a password within the range of 5..40 characters" do<br>> > > person = create(:last_name => "ruby_tuesday")<br>
> > > person.password.should_not be_nil<br>> > > (5..40) === person.password.length.should<br>> > > end<br>> > ><br>> > > Its true, it really works, tell all your friends!
<br>> ><br>> > How does that verify that a person will reject a password length of 4 or<br>> 41?<br>> ><br>> > ><br>> > ><br>> > > On 5/27/07, Sam Aaron <<a href="mailto:sam.maillists@googlemail.com">
sam.maillists@googlemail.com</a> > wrote:<br>> > > ><br>> > > > On 27 May 2007, at 8.31 pm, Andrew WC Brown wrote:<br>> > > > ><br>> > > > > I thought this would work:
<br>> > > > > person.password.length.should == (5..40)<br>> > > > ><br>> > > ><br>> > > > I think that in this case, you want to use the === operator when<br>> > > > comparing a number with a range. Instead of trying to see if both of
<br>> > > > the objects (the number and the range) are the same, the === operator<br>> > > > checks to see if the number is within the range.<br>> > > ><br>> > > > Also, make sure you surround your range with parenthesis (which you
<br>> > > > are already doing), and put the range on the left hand side of the<br>> > > > === operator for it to work. Have a look at this quick irb session<br>> > > > for an example of what I mean:
<br>> > > ><br>> > > > >> (10..50) == 15<br>> > > > => false<br>> > > > >> (10..50) === 15<br>> > > > => true<br>> > > > >> 10..50 === 15
<br>> > > > ArgumentError: bad value for range<br>> > > > from (irb):6<br>> > > > >> 15 === 10..50<br>> > > > ArgumentError: bad value for range<br>> > > > from (irb):7
<br>> > > > >> 15 === (10..50)<br>> > > > => false<br>> > > > >><br>> > > ><br>> > > > Hope this helps,<br>> > > ><br>> > > > Sam
<br>> > > ><br>> > > > ---<br>> > > > <a href="http://sam.aaron.name">http://sam.aaron.name</a><br>> > > ><br>> > > ><br>> > > > _______________________________________________
<br>> > > > rspec-users mailing list<br>> > > > <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>> > > > <a href="http://rubyforge.org/mailman/listinfo/rspec-users">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>> > > ><br>> > ><br>> > ><br>> > > _______________________________________________<br>> > > rspec-users mailing list
<br>> > > <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>> > > <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>
<br>> > ><br>> > _______________________________________________<br>> > rspec-users mailing list<br>> > <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>> > <a href="http://rubyforge.org/mailman/listinfo/rspec-users">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>> ><br>><br>><br>> _______________________________________________<br>> rspec-users mailing list<br>> <a href="mailto:rspec-users@rubyforge.org">
rspec-users@rubyforge.org</a><br>> <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>><br>_______________________________________________<br>rspec-users mailing list
<br><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br></blockquote></div><br>