Class: Test::Unit::Assertions::AssertionMessage::HashInspector
- Inherits:
-
Object
- Object
- Test::Unit::Assertions::AssertionMessage::HashInspector
- Defined in:
- lib/test/unit/assertions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each_pair ⇒ Object
-
#initialize(hash, inspected_objects) ⇒ HashInspector
constructor
A new instance of HashInspector.
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #pretty_print_cycle(q) ⇒ Object
Constructor Details
#initialize(hash, inspected_objects) ⇒ HashInspector
Returns a new instance of HashInspector.
2190 2191 2192 2193 2194 2195 2196 2197 2198 |
# File 'lib/test/unit/assertions.rb', line 2190 def initialize(hash, inspected_objects) @inspected_objects = inspected_objects @hash = {} hash.each do |key, value| key = Inspector.cached_new(key, @inspected_objects) value = Inspector.cached_new(value, @inspected_objects) @hash[key] = value end end |
Class Method Details
.target?(object) ⇒ Boolean
2185 2186 2187 |
# File 'lib/test/unit/assertions.rb', line 2185 def target?(object) object.is_a?(Hash) or ENV.equal?(object) end |
Instance Method Details
#each_pair ⇒ Object
2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 |
# File 'lib/test/unit/assertions.rb', line 2223 def each_pair keys = @hash.keys begin keys = keys.sort # FIXME: more cleverly rescue ArgumentError end keys.each do |key| yield(key, @hash[key]) end end |
#inspect ⇒ Object
2200 2201 2202 |
# File 'lib/test/unit/assertions.rb', line 2200 def inspect @hash.inspect end |
#pretty_print(q) ⇒ Object
2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 |
# File 'lib/test/unit/assertions.rb', line 2204 def pretty_print(q) q.group(1, '{', '}') do q.seplist(self, nil, :each_pair) do |k, v| q.group do q.pp(k) q.text('=>') q.group(1) do q.breakable('') q.pp(v) end end end end end |
#pretty_print_cycle(q) ⇒ Object
2219 2220 2221 |
# File 'lib/test/unit/assertions.rb', line 2219 def pretty_print_cycle(q) @hash.pretty_print_cycle(q) end |