Created
September 17, 2012 17:51
-
-
Save jimweirich/3738752 to your computer and use it in GitHub Desktop.
Experiment using two different mocking frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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