Sha256: 74a768c96b62c7ca674f703778546eadfa9f1663b15b11051b6519c3e1b5c2b8

Contents?: true

Size: 935 Bytes

Versions: 2

Compression:

Stored size: 935 Bytes

Contents

# frozen_string_literal: true

require "proto_pharm/matchers/hash_argument_matcher"

module ProtoPharm
  module Matchers
    class RequestIncludingMatcher < HashArgumentMatcher
      def ==(actual)
        if actual.respond_to?(:to_h)
          actual = actual.to_h
        end

        actual = Hash[ProtoPharm::Matchers::HashArgumentMatcher.stringify_keys!(actual, deep: true)]
        super { |key, value| inner_including(value, key, actual) }
      rescue NoMethodError
        false
      end

      private

      def inner_including(expect, key, actual)
        if actual.key?(key)
          actual_value = actual[key]
          if expect.is_a?(Hash)
            RequestIncludingMatcher.new(expect) == actual_value
          else
            expect === actual_value
          end
        else
          false
        end
      end

      def inspect
        "reqeust_including(#{@expected.inspect})"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
proto_pharm-0.7.0 lib/proto_pharm/matchers/request_including_matcher.rb
proto_pharm-0.6.0 lib/proto_pharm/matchers/request_including_matcher.rb