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

Jim Weirich jim.weirich at gmail.com
Thu May 22 23:37:44 EDT 2008

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.

Here's an example of the problem:

require File.expand_path(File.dirname(__FILE__) + "/../../config/ 
require 'spec'
require 'spec/rails'

Spec::Runner.configure do |config|
   config.mock_with :flexmock

describe "Mock Bug" do
   it "should create flexmock expectation" do
     expectation = flexmock(Object).should_receive(:xyzzy)
     expectation.class.should == FlexMock::CompositeExpectation

And here is the output of the run:

'Mock Bug should create flexmock expectation' FAILED
expected: FlexMock::CompositeExpectation,
      got: Spec::Mocks::MessageExpectation (using ==)

This is in the spec/models directory of a very simple demo Rails  
application.  If I comment out the require on environment and the  
require on spec/rails, the spec executes as expected (indicating some  
kind of interaction with Rails is part of the problem).

Anybody got any ideas on this one?  I could really use some help from  
someone who understand the RSpec mocking infrastructure better than I  
do.  I'd really like to get flexmock working in this area.

More info:  Rails 2.0.2, RSpec 1.1.3, FlexMock 0.8.1, all on Mac OS X  


-- Jim Weirich
-- jim.weirich at gmail.com

More information about the rspec-devel mailing list