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) ⇒ HashInspector
constructor
A new instance of HashInspector.
- #inspect ⇒ Object
- #pretty_print(q) ⇒ Object
- #pretty_print_cycle(q) ⇒ Object
Constructor Details
#initialize(hash) ⇒ HashInspector
Returns a new instance of HashInspector.
1565 1566 1567 |
# File 'lib/test/unit/assertions.rb', line 1565 def initialize(hash) @hash = hash end |
Class Method Details
.target?(object) ⇒ Boolean
1560 1561 1562 |
# File 'lib/test/unit/assertions.rb', line 1560 def target?(object) object.is_a?(Hash) or object == ENV end |
Instance Method Details
#each_pair ⇒ Object
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 |
# File 'lib/test/unit/assertions.rb', line 1592 def each_pair keys = @hash.keys begin keys = keys.sort # FIXME: more cleverly rescue ArgumentError end keys.each do |key| yield(Inspector.new(key), Inspector.new(@hash[key])) end end |
#inspect ⇒ Object
1569 1570 1571 |
# File 'lib/test/unit/assertions.rb', line 1569 def inspect @hash.inspect end |
#pretty_print(q) ⇒ Object
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 |
# File 'lib/test/unit/assertions.rb', line 1573 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
1588 1589 1590 |
# File 'lib/test/unit/assertions.rb', line 1588 def pretty_print_cycle(q) @hash.pretty_print_cycle(q) end |