have_received matcher missing when using Rspec 2 #45

Closed
ajmurmann opened this Issue Oct 10, 2010 · 7 comments

Comments

Projects
None yet
7 participants

When using a have received matcher on a stub I get errors like the one below under RSpec 2

Failure/Error: object.should have_received.hello
undefined method `hello' for #RSpec::Matchers::Has:0x00000003781fd8

Someone else seems to have run into the same issue:
http://github.com/rspec/rspec-core/issuesearch?state=closed&q=have_received#issue/136

wjbuys commented Nov 4, 2010

It looks like this will need changes on both sides. How about:

rr/adapters/rspec2.rb:

module RR
  module Adapters
    module RSpec2

      include RRMethods

      def setup_mocks_for_rspec
        RR.reset
      end
      def verify_mocks_for_rspec
        RR.verify
      end
      def teardown_mocks_for_rspec
        RR.reset
      end

      def have_received(method = nil)
        RR::Adapters::Rspec::InvocationMatcher.new(method)
      end
    end
  end
end

rspec/core/mocking/with_rr.rb:

require 'rr'

RSpec.configuration.backtrace_clean_patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)

module RSpec
  module Core
    module MockFrameworkAdapter
      include RR::Adapters::RSpec2
    end
  end
end
Collaborator

mcmire commented Jan 7, 2011

Really, it comes down to the fact that RR doesn't have an adapter for RSpec 2, so RSpec 2's integration with RR is currently limited to including RR::Extensions::InstanceMethods.

I just tried both of the patches above and can confirm they fix the issue.

arikfr commented Apr 4, 2011

+1 that this solves the problem.

Work for me. Would it help to have the patch as pull request?

I would put together a test case, but I imagine you're testing against rspec 1.x now. I've found appraisal a nice way to test across a range of mutually incompatible dependencies.

You'd just want different gemfiles for each version of rspec and appraisal handles the rest.

GerryG commented Feb 6, 2012

There's a little more work to complete this, right? I added the patch to with_rr.rb, and it didn't find the new file. Needed a require in rr.rb for the new file.

Contributor

james2m commented Feb 7, 2012

I've had it all running well on master on my fork for some time now so just sent up a pull request.

GerryG commented Feb 8, 2012

Ok, it appears the changes are all in for 1.0.4, now if I can only get my test example working. Had it working with new_instance_of, which is gone now, but not gone from the README.

mcmire closed this Apr 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment