Sha256: e208a6cd41cdc388de16091dcbefad394ac03f621dbd29ba05c705e8faed78d0

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

module RR
  module Adapters
    module Rspec
      def self.included(mod)
        patterns = ::Spec::Runner::QuietBacktraceTweaker::IGNORE_PATTERNS
        unless patterns.include?(RR::Errors::BACKTRACE_IDENTIFIER)
          patterns.push(RR::Errors::BACKTRACE_IDENTIFIER)
        end
      end

      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)
        InvocationMatcher.new(method)
      end

      class InvocationMatcher < SpyVerificationProxy
        attr_reader :failure_message
 
        def initialize(method = nil)
          method_missing(method) if method
        end

        def matches?(subject)
          @verification.subject = subject
          if error = RR::Space.instance.recorded_calls.match_error(@verification)
            @failure_message = error.message
            false
          else
            true
          end
        end

        def nil?
          false
        end

        def method_missing(method_name, *args, &block)
          if @verification
            @verification.send(method_name, *args)
          else
            @verification = super
          end
          self
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
jferris-rr-0.7.1.0.1239654108 lib/rr/adapters/rspec.rb
rr-0.8.1 lib/rr/adapters/rspec.rb
rr-0.8.0 lib/rr/adapters/rspec.rb