<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Aug 27, 2008 at 1:03 PM, Nick Hoffman <span dir="ltr"><<a href="mailto:nick@deadorange.com">nick@deadorange.com</a>></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 "specification" says "if it is less than 2 characters then invalid" and "if it is more than 128 characters then invalid" .<br>
<br>
But you are actually running three checks - "if less than 2", "if greater than 2 but less than 128" and "if greater than 2 and greater than 128".<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't be 129 characters<br>
- can't have a 1-letter street name<br>
- can't have an &<br>
- can't have an !<br>
- can't have a "<br>
- can't have 2 letters after the street number<br>
- can't be missing a street number<br>
- can't have only 3 characters<br>
- can'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 '<br>
- can have 1 letter after the street number<br>
- can have multiple spaces<br>
<br>
Each of the "can ..." examples are proper addresses in the sense that they're variations of:<br>
- "123 A Street With A Long Name"<br>
- "123B Maple Ave"<br>
- "123 O'Connor Street"<br>
- etc<br>
<br>
One thing that I didn't do is write examples for each invalid character. That'd be too hairy and verbose. Instead, I picked a few, and wrote examples for them, as you can see above (Eg: "can't have an &").</blockquote>
<div><br></div><div>If you want to (not necessarily advising this, but I've seen it done) you can do this:</div><div><br></div><div>['!','(',')','&'].each do |char|</div><div> it "can't have #{char}" do</div>
<div> ...</div><div> 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> </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>