That actaully makes alot of sense now.<br>Does this have to do with something State vs Behaviour verfication?<br>I&#39;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> &lt;<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>&gt; 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 &lt;<a href="mailto:omen.king@gmail.com">omen.king@gmail.com</a>&gt; wrote:<br>&gt; I&#39;m testing the validation<br>&gt; validates_length_of :password, :within =&gt; 5..40<br>&gt;<br>&gt; In this case I should be receiving a failure but I&#39;m not :(
<br>&gt;<br>&gt;&nbsp;&nbsp; it &quot;should require a password within the range of 5..40 characters&quot; do<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; person = create(:password =&gt; &#39;a&#39;)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; person.password.should_not be_nil<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; person.should
 validate_length_of(:password, 5..40)<br>&gt;&nbsp;&nbsp; end<br>&gt;<br>&gt; I&#39;m an amature tester, would you tell me how I should verify?<br>&gt; I haven&#39;t fully grasped setting testing goals<br><br>The behaviour you&#39;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&#39;s how I might handle this:<br><br>describe User do<br>&nbsp;&nbsp;it &quot;should reject a password of length 4&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;User.create(:password =&gt; &quot;1234&quot;).should have(1).error_on(:password)<br>&nbsp;&nbsp;end
<br>&nbsp;&nbsp;it &quot;should accept a password of length 5&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;User.create(:password =&gt; &quot;12345&quot;).should have(0).errors_on(:password)<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;it &quot;should accept a password of length 40&quot; do<br>
&nbsp;&nbsp;&nbsp;&nbsp;User.create(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:password =&gt; &quot;1234567890123456789012345678901234567890&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;).should have(0).errors_on(:password)<br>&nbsp;&nbsp;end<br>&nbsp;&nbsp;it &quot;should reject a password of length 41&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;User.create
(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:password =&gt; &quot;12345678901234567890123456789012345678901&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;).should have(1).error_on(:password)<br>&nbsp;&nbsp;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>&gt;<br>&gt; On 5/27/07, David Chelimsky &lt;<a href="mailto:dchelimsky@gmail.com">dchelimsky@gmail.com</a>&gt; wrote:<br>&gt; &gt;<br>&gt; &gt; On 5/27/07, Andrew WC Brown &lt;<a href="mailto:omen.king@gmail.com">
omen.king@gmail.com</a> &gt; wrote:<br>&gt; &gt; &gt;&nbsp;&nbsp; it &quot;should require a password within the range of 5..40 characters&quot; do<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; person = create(:last_name =&gt; &quot;ruby_tuesday&quot;)<br>
&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; person.password.should_not be_nil<br>&gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; (5..40) === person.password.length.should<br>&gt; &gt; &gt;&nbsp;&nbsp; end<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; Its true, it really works, tell all your friends!
<br>&gt; &gt;<br>&gt; &gt; How does that verify that a person will reject a password length of 4 or<br>&gt; 41?<br>&gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; On 5/27/07, Sam Aaron &lt;<a href="mailto:sam.maillists@googlemail.com">
sam.maillists@googlemail.com</a> &gt; wrote:<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; On 27 May 2007, at 8.31 pm, Andrew WC Brown wrote:<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt; I thought this would work:
<br>&gt; &gt; &gt; &gt; &gt; person.password.length.should == (5..40)<br>&gt; &gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; I think that in this case, you want to use the === operator when<br>&gt; &gt; &gt; &gt; comparing a number with a range. Instead of trying to see if both of
<br>&gt; &gt; &gt; &gt; the objects (the number and the range) are the same, the === operator<br>&gt; &gt; &gt; &gt; checks to see if the number is within the range.<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Also, make sure you surround your range with parenthesis (which you
<br>&gt; &gt; &gt; &gt; are already doing), and put the range on the left hand side of the<br>&gt; &gt; &gt; &gt; === operator for it to work. Have a look at this quick irb session<br>&gt; &gt; &gt; &gt; for an example of what I mean:
<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; &gt;&gt; (10..50) == 15<br>&gt; &gt; &gt; &gt; =&gt; false<br>&gt; &gt; &gt; &gt; &gt;&gt; (10..50) === 15<br>&gt; &gt; &gt; &gt; =&gt; true<br>&gt; &gt; &gt; &gt; &gt;&gt; 10..50 === 15
<br>&gt; &gt; &gt; &gt; ArgumentError: bad value for range<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):6<br>&gt; &gt; &gt; &gt; &gt;&gt; 15 === 10..50<br>&gt; &gt; &gt; &gt; ArgumentError: bad value for range<br>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):7
<br>&gt; &gt; &gt; &gt; &gt;&gt; 15 === (10..50)<br>&gt; &gt; &gt; &gt; =&gt; false<br>&gt; &gt; &gt; &gt; &gt;&gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Hope this helps,<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; Sam
<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; ---<br>&gt; &gt; &gt; &gt; <a href="http://sam.aaron.name">http://sam.aaron.name</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt; &gt; _______________________________________________
<br>&gt; &gt; &gt; &gt; rspec-users mailing list<br>&gt; &gt; &gt; &gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; &gt; &gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt; &gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt;<br>&gt; &gt; &gt; _______________________________________________<br>&gt; &gt; &gt; rspec-users mailing list
<br>&gt; &gt; &gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; &gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>
<br>&gt; &gt; &gt;<br>&gt; &gt; _______________________________________________<br>&gt; &gt; rspec-users mailing list<br>&gt; &gt; <a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>&gt; &gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">
http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt; &gt;<br>&gt;<br>&gt;<br>&gt; _______________________________________________<br>&gt; rspec-users mailing list<br>&gt; <a href="mailto:rspec-users@rubyforge.org">
rspec-users@rubyforge.org</a><br>&gt; <a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>&gt;<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>