Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created September 17, 2012 17:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimweirich/3738752 to your computer and use it in GitHub Desktop.
Save jimweirich/3738752 to your computer and use it in GitHub Desktop.
Experiment using two different mocking frameworks
require 'flexmock/dual'
RSpec.configure do |config|
config.mock_with FlexMock.flexmock_and(:rspec)
end
describe "Dual Mocking" do
before do
@rm = mock("with rspec")
@rm.should_receive(:foo)
@fm = flexmock("with flexmock")
@fm.should_receive(:bar).once
end
it "satisfies both" do
@rm.foo
@fm.bar
end
# The following three spec will fail,
# due to one or more of the mocking
# frameworks complaining about expectations.
it "only rspec is happy" do
@rm.foo
end
it "only flexmock is happy" do
@fm.bar
end
it "neither are happy" do
end
end
require 'flexmock/rspec'
class FlexMock
module Dual
module DummyAdaptor
def setup_mocks_for_rspec
end
def verify_mocks_for_rspec
end
def teardown_mocks_for_rspec
end
end
module DualMocksAdaptor
include DummyAdaptor
include FlexMock::MockContainer
def self.framework_name; :dual_mocks end
include FlexMock::MockContainer
def setup_mocks_for_rspec
super
end
def verify_mocks_for_rspec
flexmock_verify
super
end
def teardown_mocks_for_rspec
flexmock_close
super
end
end
end
def self.flexmock_and(other)
require "rspec/core/mocking/with_#{other}"
FlexMock::Dual::DualMocksAdaptor.send(:include, RSpec::Core::MockFrameworkAdapter)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment