Switching mocking frameworks in a suite is currently an "all at once" deal because there is no support for using more than one mocking framework at a time.
@jimweirich is working on a workaround for this in flexmock, but it depends on paths that are internal to rspec: https://gist.github.com/3738752
Let's consider making the adapters shipped w/ RSpec composable, so that we can support more than one, e.g.
RSpec.configure do |c|
c.mock_with :rspec, :flexmock, :mocha, :rr
I realize, btw, that there are serious downsides to consider. The biggest problem I see is that rspec-mocks now supports any_instance, which is also supported by mocha. If we compose the adapters as in @jimweirich's gist (linked above) then the last adapter to attach any_instance to Object will win, which would constrain such a transition.
Also, it is very likely that people will try to use this feature to mix/match in different parts of the same suite (vs a transition) and that's a recipe for confusion.
So I'm not 100% in on this, but I wanted to get the conversation going here rather than twitter.
I wouldn't assume that any given mock framework is composable with another arbitrary framework, and I don't think there is much we can do about that without changes to the individual frameworks.
FlexMock, for its part, tries to stay out of the global namespace as much as possible. It is possible to use FlexMock mocks and another framework's mocks in the same test. You should only run into problems if you try to mock out methods on the same real object using two different frameworks.
Gimme is a spy framework that is pretty unobtrusive, it too should be fairly composable.
So while not all frameworks are composable, there are certainly combinations that could work together.
This might be a bit much, but if someone is using this as a transition, could we include a configuration option of the preferred framework? So it would try that one first, and otherwise send it down the chain (or, in this case, up the chain since the last one defined wins)?
Rearrange mocking adapters.
* Use a different module name for each adapter.
* Name the files based on the module name.
This is a stepping stone towards supporting the user
of multiple mocking adapters -- see #683.
For more background, see these gists:
@myronmarston what's the status of this issue?
Yep, quite stale. It's one of those things that it'd be nice if RSpec had but that I doubt I'll ever get to. Maybe someone will contribute it at some point, though.