Sha256: df6f5188d749849547d47ee946e321bfaec9c84c36c8350dc6a700efc724a6f2

Contents?: true

Size: 911 Bytes

Versions: 5

Compression:

Stored size: 911 Bytes

Contents

module WebMock
  module Matchers
    #this is a based on RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
    #https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
    class HashIncludingMatcher
      def initialize(expected)
        @expected = Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(expected, :deep => true).sort]
      end

      def ==(actual)
        @expected.all? {|k,v| actual.has_key?(k) && v == actual[k]}
      rescue NoMethodError
        false
      end

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

      def self.from_rspec_matcher(matcher)
        new(matcher.instance_variable_get(:@expected))
      end
    end

    #this is a based on RSpec::Mocks::ArgumentMatchers::AnyArgMatcher
    class AnyArgMatcher
      def initialize(ignore)
      end

      def ==(other)
        true
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
webmock-1.20.3 lib/webmock/matchers/hash_including_matcher.rb
webmock-1.20.2 lib/webmock/matchers/hash_including_matcher.rb
webmock-1.20.1 lib/webmock/matchers/hash_including_matcher.rb
webmock-1.20.0 lib/webmock/matchers/hash_including_matcher.rb
webmock-1.19.0 lib/webmock/matchers/hash_including_matcher.rb