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.
1546 1547 1548 |
# File 'lib/test/unit/assertions.rb', line 1546 def initialize(hash) @hash = hash end |
Class Method Details
.normalize(object) ⇒ Object
1537 1538 1539 1540 1541 1542 1543 |
# File 'lib/test/unit/assertions.rb', line 1537 def normalize(object) if target?(object) new(object) else object end end |
.target?(object) ⇒ Boolean
1533 1534 1535 |
# File 'lib/test/unit/assertions.rb', line 1533 def target?(object) object.is_a?(Hash) or object == ENV end |
Instance Method Details
#each_pair ⇒ Object
1573 1574 1575 1576 1577 1578 |
# File 'lib/test/unit/assertions.rb', line 1573 def each_pair @hash.keys.sort.each do |key| yield(self.class.normalize(key), self.class.normalize(@hash[key])) end end |
#inspect ⇒ Object
1550 1551 1552 |
# File 'lib/test/unit/assertions.rb', line 1550 def inspect @hash.inspect end |
#pretty_print(q) ⇒ Object
1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'lib/test/unit/assertions.rb', line 1554 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
1569 1570 1571 |
# File 'lib/test/unit/assertions.rb', line 1569 def pretty_print_cycle(q) q.text(@hash.empty? ? '{}' : '{...}') end |