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.
1691 1692 1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/test/unit/assertions.rb', line 1691 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
1686 1687 1688 |
# File 'lib/test/unit/assertions.rb', line 1686 def target?(object) object.is_a?(Hash) or ENV.equal?(object) end |
Instance Method Details
#each_pair ⇒ Object
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 |
# File 'lib/test/unit/assertions.rb', line 1724 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
1701 1702 1703 |
# File 'lib/test/unit/assertions.rb', line 1701 def inspect @hash.inspect end |
#pretty_print(q) ⇒ Object
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 |
# File 'lib/test/unit/assertions.rb', line 1705 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
1720 1721 1722 |
# File 'lib/test/unit/assertions.rb', line 1720 def pretty_print_cycle(q) @hash.pretty_print_cycle(q) end |