On Mon, Aug 25, 2008 at 12:53 PM, Nick Hoffman <[EMAIL PROTECTED]> wrote: > I'm not sure how much test data I should be using in my specs. I'm writing > specs for the Property model in my Rails app. Its "address" attribute is > going to be validated with this regex: > /\A\d+[a-z]? [-', a-z]{2,128}\Z/i > > At the moment, my plan is to spec out the following possibilities. A > property is invalid if its address: > 1) doesn't begin with a digit; > 2) is shorter than 2 characters; > 3) is longer than 128 characters; > > I should also test that certain characters, such as ! @ # $ etc, invalidate > a property. > > However, all of that seems like blacklisting, and achieves poor coverage of > the regular expression. > > Should I create a list of valid and invalid addresses to test against the > regex? That seems like a decent idea, but seems synonymous with fixtures. > What would you guys recommend? >
I might do something like the following... describe Property, "email validations" do ["[EMAIL PROTECTED]", "can't start with a digit", "[EMAIL PROTECTED]", "can't end with a digit" ].in_groups_of(2) do |email, description| it description do prop = Property.new :email => email prop.should_not be_valid prop.should have(1).error_on(:email) end end end -- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users