[rspec-users] Stubs breaking other things

David Goodlad dgoodlad at gmail.com
Tue Dec 12 14:34:16 EST 2006

Hi All

I'm working on converting some existing controller specs to use mocks
and stubs rather than real ActiveRecord objects in a Rails project.
In one of my controller actions, I use a database transaction.  So,
the obvious thing to do is have this in my setup block:


Firstly, is there an easy way to have that stub yield to the block
passed to any #transaction calls?  I'm sure there's an easy way to do
it but I can't seem to find it.

Secondly, it seems that stubbing the transaction method in one context
breaks all sorts of other stuff.  I'm assuming that since AR uses
transactions for saving records, any project that gets saved in code
that actually uses the real Project model instead of a mock is now
broken.  Is the stub code, in the case of a partial mock, supposed to
revert any methods it overrides upon teardown?


Dave Goodlad
dgoodlad at gmail.com or dave at goodlad.ca

More information about the rspec-users mailing list