<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Aug 27, 2008 at 1:03 PM, Nick Hoffman <span dir="ltr">&lt;<a href="mailto:nick@deadorange.com">nick@deadorange.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d">On 2008-08-27, at 12:57, Rahoul Baruah wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
For this, trivial, example, I find that far too verbose.<br>
<br>
The &quot;specification&quot; says &quot;if it is less than 2 characters then invalid&quot; and &quot;if it is more than 128 characters then invalid&quot; .<br>
<br>
But you are actually running three checks - &quot;if less than 2&quot;, &quot;if greater than 2 but less than 128&quot; and &quot;if greater than 2 and greater than 128&quot;.<br>
<br>
B<br>
<br>
<br>
Rahoul Baruah<br>
</blockquote>
<br></div>
This is what I ended up with:<br>
<br>
Property addresses that are valid<br>
- can&#39;t be 129 characters<br>
- can&#39;t have a 1-letter street name<br>
- can&#39;t have an &amp;<br>
- can&#39;t have an !<br>
- can&#39;t have a &quot;<br>
- can&#39;t have 2 letters after the street number<br>
- can&#39;t be missing a street number<br>
- can&#39;t have only 3 characters<br>
- can&#39;t be empty<br>
- can have 128 characters<br>
- can have 127 characters<br>
- can have only 5 characters<br>
- can have only 4 characters<br>
- can have a ,<br>
- can have a -<br>
- can have a &#39;<br>
- can have 1 letter after the street number<br>
- can have multiple spaces<br>
<br>
Each of the &quot;can ...&quot; examples are proper addresses in the sense that they&#39;re variations of:<br>
- &quot;123 A Street With A Long Name&quot;<br>
- &quot;123B Maple Ave&quot;<br>
- &quot;123 O&#39;Connor Street&quot;<br>
- etc<br>
<br>
One thing that I didn&#39;t do is write examples for each invalid character. That&#39;d be too hairy and verbose. Instead, I picked a few, and wrote examples for them, as you can see above (Eg: &quot;can&#39;t have an &amp;&quot;).</blockquote>
<div><br></div><div>If you want to (not necessarily advising this, but I&#39;ve seen it done) you can do this:</div><div><br></div><div>[&#39;!&#39;,&#39;(&#39;,&#39;)&#39;,&#39;&amp;&#39;].each do |char|</div><div>&nbsp;&nbsp;it &quot;can&#39;t have #{char}&quot; do</div>
<div>&nbsp;&nbsp; &nbsp;...</div><div>&nbsp;&nbsp;end</div><div>end</div><div><br></div><div>That makes the output very verbose, but the spec file is easy to grok.</div><div>&nbsp;</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="Wj3C7c"><br>
<br>
Cheers,<br>
Nick<br>
_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org" target="_blank">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</div></div></blockquote></div><br></div>