[rspec-users] validate_presence_of

Stephen Eley sfeley at gmail.com
Thu Feb 19 09:20:52 EST 2009

On Thu, Feb 19, 2009 at 12:58 AM, David Chelimsky <dchelimsky at gmail.com> wrote:
>> Also, while I used to be very anal and write "should
>> have(1).error_on(:login)" and such, I eventually realized that there's
>> no point.  Checking on 'valid?' is entire and sufficient.
> I think this depends on whether or not error messages are part of the
> conversation w/ the customer. If not, that seems fine.

But "should have(1).error_on(:login)" isn't a test on error messages.
It's a test on a key called :login.  The conversation with the
customer has no bearing on that; the customer's never asked about the
errors data structure.

I do check for error messages making it to the user, but not in my
model specs.  Those get checked in my request specs.  (Or my Cucumber
features, whichever I'm doing that day.)  So again, it's covered; just
not twice.

> But my validation specs do tend to be closely tied to AR methods like
> valid?(), which, as your example suggests, is impeding my ability to
> choose a different ORM lib. Time for some re-thinking!

To be fair, the only reason the tests I quoted work when I switched to
Datamapper is because DM coincidentally (or not) uses the same
"valid?" method that AR does.  Eventually you do have to hit your API.
 I just like to hit it at the highest level that proves the behavior I
care about.

Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine

More information about the rspec-users mailing list