Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rspec-multi-mock

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rspec-multi-mock

  • 0.3.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

rspec-multi-mock Build Status

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

  • For rspec 1.3.1 refer to v0.1.0
  • For rspec 2.x and not_a_mock support refer to v0.2.1

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

  • You are merging two big projects and they use different mocking frameworks for unit testing.
  • You want to try a new mocking framework with cleaner syntax and some new features.

Since RSpec does not support multiple mocking frameworks, we might hesitate to pick up these tasks because

  • There could be less time and it needs some effort to convert all the specs to use new mocking framework.
  • The new mocking framework may not yet provide all the features available in the current mocking framework.

Using this gem you can

  • Start moving specs incrementally to new framework
  • Start using new framework for new specs. This will reduce the number of specs need to be converted at the end.
  • Use both mocking frameworks till the new one provides all the required features.

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.

  • The expectations set using the un-configured mocking framework will not be verified.
  • The methods mocked or stubbed using the un-configured mocking framework will not be cleaned up after the spec run is completed. This becomes a serious issue if it is a class method

FAQs

Package last updated on 19 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc