[rspec-users] How to test update_attribute with mocha?

Matt Wynne matt at mattwynne.net
Fri May 15 01:52:23 EDT 2009

On 14 May 2009, at 14:20, Phlip wrote:

> Matt Wynne wrote:
>> I've got a reason. You're coupling the tests for this simple little  
>> controller class to all the infrastructure and dependencies needed  
>> to write the record to the database and reload it again. As easy as  
>> Rails makes it for us to manage our database schemas, gratuitously  
>> introducing dependencies in your code like this is a bad habit to  
>> get into. It can lead to tests that are fragile to failing when  
>> code is changed far away from the place they're apparently testing.  
>> The tests also run slowly, which makes working on systems written  
>> like this boring.
> The point of unit tests (which include the alleged "functional  
> tests" in Rails) is to fail more often than production code would  
> fail. Not less often.

Yep, I agree that would be silly.

On the other hand, if the tests fail for no good reason all the time  
because they're fragile, people may stop listening to them, and maybe  
eventually stop writing them. The argument I'm making is really just  
for slowing down and taking a little more care, with the eventual  
benefit of tests that are trustworthy and easy to maintain. I would  
imagine that's your goal too, but we apparently have different  
approaches :)

Matt Wynne

More information about the rspec-users mailing list