[rspec-users] validate_presence_of

Zach Dennis zach.dennis at gmail.com
Wed Feb 18 20:53:31 EST 2009

On Wed, Feb 18, 2009 at 7:39 PM, Fernando Perez <lists at ruby-forum.com> wrote:
> Yi Wen wrote:
>> Hello,
>> according to this post:
>> http://blog.davidchelimsky.net/2009/1/13/rspec-1-1-12-is-released
>> I should be able to write:
>> describe User do
>>   it {should valdate_presence_of(:login)}
>> end
> What's the point in testing validates_presence_of for a model?


It definitely doesn't provide any design benefits since that decision
has already been made for you, but it does provide a developer-level
example to communicate the behaviour of a model, and it covers
regression. I prefer both of these.

The flip-side would be that if you and your customer wrote scenarios
which communicated the same intent, as well as were executable then
you'd also achieve these benefits. While this works, if often doesn't
fit the bill for a scenario very well (I prefer less verbose, higher
level declarative scenarios) and it misses out on providing developer
documentation for how a particular object should behave.

For me, a non-option is to have neither of these in place.

>  It's
> already tested in the framework, and so readable that a quick glance on
> the model says it all. I would only test it if I added some bizarre
> behavior with procs and so on.

What's tested in the framework is that validates_presence works. What
isn't tested is that your Item model needs to ensure it always belongs
to an :order. I'm more interested in the fact that Item always
requires an order. I expected the Rails developers to do their due
diligence to ensure validates_presence_of works in all of its

> What's the community's position about that?

What Pat said.

> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Zach Dennis

More information about the rspec-users mailing list