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.clone
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?



22
23
24
25
# File 'lib/rr/wildcard_matchers/hash_including.rb', line 22

def ==(other)
  return false unless other.is_a?(self.class)
  self.expected_hash == other.expected_hash
end

#inspectObject



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

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

#wildcard_match?(other) ⇒ Boolean

Returns:



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

def wildcard_match?(other)
  return true if self == other
  expected_hash.each_pair do |key, value|
    return false unless other.has_key?(key) && other[key] == expected_hash[key]
  end
  return true
end