[rspec-users] How much test data to use in specs

David Chelimsky dchelimsky at gmail.com
Mon Aug 25 18:00:58 EDT 2008

On Mon, Aug 25, 2008 at 3:02 PM, Zach Dennis <zach.dennis at gmail.com> wrote:
> On Mon, Aug 25, 2008 at 2:50 PM, Nick Hoffman <nick at deadorange.com> wrote:
>> On 2008-08-25, at 13:29, Zach Dennis wrote:
>>> I might do something like the following...
>>> describe Property, "email validations" do
>>>  ["1invalid.email at example.com", "can't start with a digit",
>>>   "invalid.email2 at example.com", "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
>> Hi Zach. That's a great way of iterating over test data. Do you have any
>> suggestions for how much test data to use?
> I'd probably start with the first invalid email/description that I can
> think of. Perhaps it can't start with a digit. Then I'd update the
> regexp to reflect that. Next I'd add a second invalid
> email/description and update the regexp to reflect that. Rinse and
> repeat until your regexp is where you need it.

This is nit-picky, I realize, but saying "until your regexp is where
you need it" suggests that you'll know when you get there by looking
at the regexp. I'd suggest that you know when you get there by looking
at the code examples and feeling confident that you've covered all of
the edge cases.

> This should help you
> not add redundant emails which test the same thing. When you get to
> the case where you allow from 2 up to 128 characters, you could just
> test those two edge cases (rather than emails which 2 characters, 3
> characters, 4 characters, ... 128 characters.

If the boundaries are 2 and 128, I would test 1,2,3,127,128,129 - the
boundary and either side of it. Might seem like overkill, but I've
seen a bug or two make its way to production because the boundary
wasn't clearly understood.


> --
> Zach Dennis
> http://www.continuousthinking.com
> http://www.mutuallyhuman.com
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list