Class: HashMap::Matchers::HashMappedMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ HashMappedMatcher

Returns a new instance of HashMappedMatcher.



11
12
13
14
15
16
# File 'lib/hash_map/matchers.rb', line 11

def initialize(key)
  @key = key
  @error = []
  @description_messages = []
  @failure_messages = []
end

Instance Attribute Details

#description_messagesObject (readonly)

Returns the value of attribute description_messages.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def description_messages
  @description_messages
end

#expectedObject (readonly)

Returns the value of attribute expected.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def expected
  @expected
end

#expected_providedObject (readonly)

Returns the value of attribute expected_provided.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def expected_provided
  @expected_provided
end

#failure_messagesObject (readonly)

Returns the value of attribute failure_messages.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def failure_messages
  @failure_messages
end

#from_keyObject (readonly)

Returns the value of attribute from_key.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def from_key
  @from_key
end

#keyObject (readonly)

Returns the value of attribute key.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def key
  @key
end

#mapped_has_keyObject (readonly)

Returns the value of attribute mapped_has_key.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def mapped_has_key
  @mapped_has_key
end

#mapped_hashObject (readonly)

Returns the value of attribute mapped_hash.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def mapped_hash
  @mapped_hash
end

#original_hashObject (readonly)

Returns the value of attribute original_hash.



8
9
10
# File 'lib/hash_map/matchers.rb', line 8

def original_hash
  @original_hash
end

Instance Method Details

#and_eq(expected) ⇒ Object



37
38
39
40
41
# File 'lib/hash_map/matchers.rb', line 37

def and_eq(expected)
  @expected_provided = true
  @expected = expected
  self
end

#descriptionObject



23
24
25
# File 'lib/hash_map/matchers.rb', line 23

def description
  description_messages.join(', ')
end

#failure_messageObject



27
28
29
# File 'lib/hash_map/matchers.rb', line 27

def failure_message
  failure_messages.join(', ')
end

#failure_message_when_negatedObject



43
44
45
# File 'lib/hash_map/matchers.rb', line 43

def failure_message_when_negated
  "expect to not #{description}"
end

#from(original_hash, *from_key) ⇒ Object



31
32
33
34
35
# File 'lib/hash_map/matchers.rb', line 31

def from(original_hash, *from_key)
  @original_hash = original_hash
  @from_key = from_key
  self
end

#matches?(hash) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/hash_map/matchers.rb', line 18

def matches?(hash)
  @mapped_hash = hash
  _has_key && _from && equality
end