Allows multiple mock frameworks to be in action in RSpec. This version is for rspec >=2.3.0.
gem install rspec-multi-mock
If you are using bundler add the dependency in Gemfile
gem 'rspec-multi-mock', :group => :test
Configure multi-mock for RSpec runner (Usually done in spec_helper.rb)
RSpec.configure do |config|
config.mock_with MultiMock::Adapter.for(:rspec, :mocha, :rr, ::NewMockFramework::RSpecAdapter)
end
As shown above you can use a symbol for frameworks listed above. The usage of adapter module directly may not work completely if the adapter module contains any extensions methods to be used in specs. For instance RR rspec adapter includes both the adapter methods and the extension methods.
There are cases where you might have to use two different mocking in the same project(for a while). It could be because
Since RSpec does not support multiple mocking frameworks, we might hesitate to pick up these tasks because
Using this gem you can
Please note that using multiple mocking frameworks can create a lot of confusion in the team. So make sure that the end goal is to use single mocking framework(Your favorite one!). Use this gem only during the transition phase.
If you are already using multiple mock frameworks with just one mock framework configured in spec runner, the mocks may not be working completely as you expected.