Class: RR::WildcardMatchers::HashIncluding

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/wildcard_matchers/hash_including.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_hash) ⇒ HashIncluding

Returns a new instance of HashIncluding.



6
7
8
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 6

def initialize(expected_hash)
  @expected_hash = expected_hash.dup
end

Instance Attribute Details

#expected_hashObject (readonly)

Returns the value of attribute expected_hash.



4
5
6
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 4

def expected_hash
  @expected_hash
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



19
20
21
22
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 19

def ==(other)
  other.is_a?(self.class) &&
  other.expected_hash == self.expected_hash
end

#inspectObject



25
26
27
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 25

def inspect
  "hash_including(#{expected_hash.inspect})"
end

#wildcard_match?(other) ⇒ Boolean

Returns:



10
11
12
13
14
15
16
17
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 10

def wildcard_match?(other)
  self == other || (
    other.is_a?(Hash) &&
    expected_hash.all? { |k, v|
      other.key?(k) && other[k] == expected_hash[k]
    }
  )
end