[rspec-users] More on collection proxies

Jay Levitt lists-rspec at shopwatch.org
Wed Jan 24 09:08:10 EST 2007


Jay Levitt wrote:
> David Chelimsky wrote:
>> User.should_receive(:validates_presence_of).with(:email)
> Wow - I never thought of it like that.  I think (as a new convert to 
> mocks) that type of mock is a little too specific and un-DRY for my 
> taste, though; it feels like specifying that "line 6 of method foo 
> should be an if statement".  There's double-entry bookkeeping, and then 
> there's keeping two sets of books.

While I'm out on this limb, I'm gonna say that, given the way Rails 
validations are structured, it's better to use state-based testing than 
interaction-based testing!

validates_presence_of is a bad example, because the two methods are 
practically interchangeable.  But consider a validation that uses a 
regex to verify a legal IP address.  Do you want your specs to repeat 
the regex, or do you want to test various legal and illegal IP-address 
strings and see what breaks?  To me, it's the second one that's actually 
testing the behavior of the application.


Jay



More information about the rspec-users mailing list