Re: Strange Little Problem

Bob Showalter
Wed, 26 Sep 2007 20:19:59 -0000

On 9/26/07, Rob Biedenharn
<Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org>
wrote:
>
> On Sep 26, 2007, at 2:44 PM, Bob Showalter wrote:
> > On 9/26/07, Rob Biedenharn
<Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:
> >> However, all you''re doing is testing that the
validates_uniqueness_of
> >> works.
> >
> > Rob, is that *all* he''s doing? The test is too elaborate, but
a case
> > could be made that this is a regression test for the business rule
> > that "Member numbers must be unique".
> >
> > It would protect him from coming along later and inadvertently
> > removing that validation rule.
> >
> > I agree that we shouldn''t be testing Rails itself.
>
> Stu Halloway addressed this at erubycon in Columbus,OH this summer.
>
> Blog:   http://relevancellc.com/2007/7/17/posted-slides-how-not-to-test-
> validations
> Slides: http://relevancellc.com/assets/2007/7/17/KeepingTestsDry.pdf
>
> If you''re interested in a test to alert you when/if a validation
is
> removed accidentally, then you should be devising a test for *that*
> (presence) and letting Rails make sure that validates_*_of does the
> right thing.

Well, that sounds good in theory. But in those slides, slide 18 looks
great but the stuff on 19/20 is a mess!

Devising a test for the presence of validates_uniqueness_of (instead
of exercising it) is non-trivial. And I''m not sure that''s
somehow
"better" or "DRY''er" than just trying to create a
duplicate and seeing
it fail.

I''m really not trying to test whether I have a validates_uniqueness_of
declaration, and I''m not trying to test whether
validates_uniqueness_of works in the abstract (the test doesn''t prove
that anyway). Instead, I''m trying to test that my model
doesn''t allow
the number to be duplicated (regardless of the details of the
implementation).

IMHO, something like slide 17 is the correct approach, and not 18.

Cheers,
Bob