public
Created

Experiment using two different mocking frameworks

  • Download Gist
dual_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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
flexmock_dual.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.