Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Support multiple mocking frameworks #683

dchelimsky opened this Issue Sep 18, 2012 · 7 comments


None yet
8 participants

dchelimsky commented Sep 18, 2012

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

dchelimsky commented Sep 18, 2012

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.

CoryFoy commented Sep 20, 2012

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)?

myronmarston added a commit that referenced this issue Nov 16, 2013

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:

* https://gist.github.com/myronmarston/5584693
* https://gist.github.com/jimweirich/3738752

@myronmarston myronmarston added this to the Post 3.0 milestone Mar 24, 2014


mrageh commented Feb 23, 2016

@myronmarston what's the status of this issue?


JonRowe commented Feb 23, 2016

Very stale...


myronmarston commented Feb 23, 2016

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.

@xaviershay xaviershay added the Feature label Jan 15, 2017


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment