have_received matcher fails with Minitest
Created by: randycoulman
I'm trying to use rspec-mock's spies in a Minitest (not Minitest::Spec
) project and am running into an error that I don't know how to solve.
I'm using Minitest 5.7, rspec-mocks 3.2.1, and Ruby 2.1.3p342.
As near as I can tell, I'm not running into any conflicts between Minitest and rspec-mocks. When I trace through the code, I seem to be hitting only methods in rspec-mocks.
When I run the example below, I get the following error. If I run an equivalent example written with RSpec, everything works as expected.
1) Error:
SpyTest#test_accepts_invitation:
NoMethodError: undefined method `setup_expectation' for #<RSpec::Mocks::Matchers::HaveReceived:0xb8dae0cc>
/usr/local/lib/ruby/gems/2.1.0/gems/rspec-mocks-3.2.1/lib/rspec/mocks/targets.rb:45:in `define_matcher'
/usr/local/lib/ruby/gems/2.1.0/gems/rspec-mocks-3.2.1/lib/rspec/mocks/targets.rb:14:in `block in delegate_to'
spies.rb:33:in `test_accepts_invitation'
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
require "minitest/autorun"
require "rspec/mocks"
class User
def accept_invitation(invitation)
invitation.accept
end
end
module RSpecMocksIntegration
include ::RSpec::Mocks::ExampleMethods
def before_setup
::RSpec::Mocks.setup
super
end
def after_teardown
super
::RSpec::Mocks.verify
ensure
::RSpec::Mocks.teardown
end
end
class SpyTest < Minitest::Test
include RSpecMocksIntegration
def test_accepts_invitation
invitation = spy("invitation")
user = User.new
user.accept_invitation(invitation)
expect(invitation).to have_received(:accept)
end
end