Class: Test::Unit::Assertions::AssertionMessage::HashInspector

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/assertions.rb

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HashInspector) initialize(hash, inspected_objects)



1625
1626
1627
1628
1629
1630
1631
1632
1633
# File 'lib/test/unit/assertions.rb', line 1625

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

+ (Boolean) target?(object)



1620
1621
1622
# File 'lib/test/unit/assertions.rb', line 1620

def target?(object)
  object.is_a?(Hash) or ENV.equal?(object)
end

Instance Method Details

- (Object) each_pair



1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
# File 'lib/test/unit/assertions.rb', line 1658

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

- (Object) inspect



1635
1636
1637
# File 'lib/test/unit/assertions.rb', line 1635

def inspect
  @hash.inspect
end

- (Object) pretty_print(q)



1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
# File 'lib/test/unit/assertions.rb', line 1639

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

- (Object) pretty_print_cycle(q)



1654
1655
1656
# File 'lib/test/unit/assertions.rb', line 1654

def pretty_print_cycle(q)
  @hash.pretty_print_cycle(q)
end