Class: WebMock::Matchers::HashIncludingMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/webmock/matchers/hash_including_matcher.rb

Overview

this is a based on RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ HashIncludingMatcher

Returns a new instance of HashIncludingMatcher.



6
7
8
# File 'lib/webmock/matchers/hash_including_matcher.rb', line 6

def initialize(expected)
  @expected = Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(expected, :deep => true).sort]
end

Class Method Details

.from_rspec_matcher(matcher) ⇒ Object



20
21
22
# File 'lib/webmock/matchers/hash_including_matcher.rb', line 20

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

Instance Method Details

#==(actual) ⇒ Object



10
11
12
13
14
# File 'lib/webmock/matchers/hash_including_matcher.rb', line 10

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

#inspectObject



16
17
18
# File 'lib/webmock/matchers/hash_including_matcher.rb', line 16

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