[rspec-devel] RSpec mocks running when Flexmock is configured

David Chelimsky dchelimsky at gmail.com
Sat May 24 09:15:35 EDT 2008

On May 23, 2008, at 6:20 PM, Jim Weirich wrote:

> On May 22, 2008, at 11:37 PM, Jim Weirich wrote:
>> I've been debugging a problem with mocks in RSpec.  I've configured  
>> RSpec to use flexmock, but the RSpec mocking framework still adds  
>> its should_receive method onto every object in the system,  
>> including flexmock objects.  These RSpec mocks are never torn down  
>> because the teardown mechanism is invoking flexmock's teardown.
> Ok, I've investigated the problem further.  The issue is caused in  
> spec/rails by the inclusion of the render_observer file.   
> Render_observer unconditionally loads the rspec mocks file without  
> checking for configured mock library.
> This is problematic in two areas:
> (1) RSpec mock teardown facility only supports a single mock library  
> (AFAIK, I recall being told this was a design decision).  Once a  
> different mock library is configured, RSpec mocks will not be torn  
> down.
> (2) The RSpec mock library globally installs a should_receive method  
> on every object in the system, interfering with other mock libraries.
> Solutions I see are:
> (A) Fix render_observer to work with the configured mock library.
> (B) Allow RSpec to support multiple simultaneous mocking frameworks.

Hey Jim - thanks for taking the time to figure this out.

I think that changing rspec to support multiple mocking frameworks  
would require removing the Object-invasion you speak of. If I were  
starting from scratch, that's definitely the direction I'd want to go.  
Given that there are a lot of examples in the world that exploit that,  
it would be counter-productive for us to change that decision at this  

Changing render_observer to support different libraries would require  
rspec to follow the maintenance of those libraries. That's not really  
a viable option in my view.

We can, however, do a better job of decoupling things. I have some  
thoughts about that but I have no time right this second so I'll  
follow up later today.


More information about the rspec-devel mailing list