Class: Deep::Matchers::HashEnclosingArray
- Inherits:
-
Object
- Object
- Deep::Matchers::HashEnclosingArray
- Defined in:
- parser/spec/lib/deep/hash_enclosed_in_array.rb
Overview
Hash (subject) ancloses Array wit ha bunch of Hases inside. Each aHas is then tested by KeyNamesOfEnclosedHash
{ :foos => <--- subject
[
{ :foo (or :name) => ...,
:bar => ...,
},
{ :foo (or :name) => ...,
:bar => ...,
},
]
}
Instance Method Summary (collapse)
- - (Object) description
- - (Object) failure_message_for_should
- - (Object) failure_message_for_should_not
- - (Boolean) matches?(target)
Instance Method Details
- (Object) description
96 97 98 |
# File 'parser/spec/lib/deep/hash_enclosed_in_array.rb', line 96 def description "enclose Arrays of Hashes with key #{@target.keys}" end |
- (Object) failure_message_for_should
100 |
# File 'parser/spec/lib/deep/hash_enclosed_in_array.rb', line 100 def ; description + @failure; end |
- (Object) failure_message_for_should_not
101 |
# File 'parser/spec/lib/deep/hash_enclosed_in_array.rb', line 101 def ; 'not ' + description end |
- (Boolean) matches?(target)
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'parser/spec/lib/deep/hash_enclosed_in_array.rb', line 104 def matches? target @target = target result = true @failure = ":\n" if @target.is_a? Hash target.each do |key,array| if array.is_a? Array res = KeyNamesOfEnclosedHash.new(key).matches?(array) result &&= res @failure << { key => array}.inspect unless res end end end result end |