Sha256: 497289eaced1b66d00c3c12bccec1e83eccaa069c65110059f42b3ff1008eae8

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module RR
  module Expectations
    class ArgumentEqualityExpectation #:nodoc:
      attr_reader :expected_arguments

      def initialize(*expected_arguments)
        @expected_arguments = expected_arguments
      end

      def exact_match?(*arguments)
        return false unless arguments.length == @expected_arguments.length
        arguments.each_with_index do |arg, index|
          return false unless equality_match(@expected_arguments[index], arg)
        end
      end

      def wildcard_match?(*arguments)
        return false unless arguments.length == @expected_arguments.length
        arguments.each_with_index do |arg, index|
          expected_argument = @expected_arguments[index]
          if expected_argument.respond_to?(:wildcard_match?)
            return false unless expected_argument.wildcard_match?(arg)
          else
            return false unless equality_match(expected_argument, arg)
          end
        end
        return true
      end

      def ==(other)
        @expected_arguments == other.expected_arguments
      end

      protected
      def equality_match(arg1, arg2)
        arg1.respond_to?(:__rr__eql?) ? arg1 == arg2 : arg1.eql?(arg2)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rr-0.4.7 lib/rr/expectations/argument_equality_expectation.rb
rr-0.4.6 lib/rr/expectations/argument_equality_expectation.rb
rr-0.4.5 lib/rr/expectations/argument_equality_expectation.rb