endeepak / rspec-multi-mock

Allows multiple mock frameworks to be in action in RSpec (With no monkey patching on Rspec)
https://github.com/endeepak/rspec-multi-mock
MIT License
21 stars 5 forks source link

rspec-multi-mock Build Status

Allows multiple mock frameworks to be in action in RSpec. This version is for rspec >=2.3.0.

Installation

    gem install rspec-multi-mock

Usage

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.

When & How is this useful?

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.

Note

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.