[rspec-users] validate_presence_of

David Chelimsky dchelimsky at gmail.com
Thu Feb 19 13:25:34 EST 2009

On Thu, Feb 19, 2009 at 11:38 AM, Mark Wilden <mark at mwilden.com> wrote:
> On Wed, Feb 18, 2009 at 9:40 PM, Stephen Eley <sfeley at gmail.com> wrote:
>> On Wed, Feb 18, 2009 at 11:42 PM, Yi Wen <hayafirst at gmail.com> wrote:
>> validates_presence_of happens to be the name of the method in
>> ActiveRecord that does that.  But if you decide to write your own
>> check_to_see_if_this_thingy_is_in_my_whatsis() method that does the
>> same thing, a good *behavior* spec will not break.  Because the
>> behavior remains the same.
> I think you're talking about state-based, blackbox testing, rather
> than behavior-based whitebox testing. RSpec unit tests are all about
> speccing that one object calls another object's method at the right
> time.

This is true in cases where the object delegates responsibility and
that delegation is significant. If a collaborator is polymorphic, and
the correct collaborator is chosen based on conditions external to the
subject, then it makes sense to spec interactions.

If the collaborator connects to an external resource like a database
or a network, then stubbing the collaborator makes good sense.

On the contrary, if the collaborator is created internally and is
always the same object and does not require any setup outside of the
subject, then spec'ing interactions doesn't make sense.

Make sense?

> The idea being that if that behavior occurs, and that the other
> object's method has been similarly tested, that you're OK.

With the caveat that somewhere there is some level of integration
testing going on. Although it looks like J.B. Rainsberger disagrees:
http://agile2009.agilealliance.org/node/708 (you have to have an
account to view this - but the title of his proposed talk is
"Integration Tests are a Scam"). I don't know enough of the detail of
his arguments to argue them here, but it seems like an interesting


> ///ark
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list