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

#initialize(hash, inspected_objects) ⇒ HashInspector

Returns a new instance of HashInspector.



1880
1881
1882
1883
1884
1885
1886
1887
1888
# File 'lib/test/unit/assertions.rb', line 1880

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

Returns:

  • (Boolean)


1875
1876
1877
# File 'lib/test/unit/assertions.rb', line 1875

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

Instance Method Details

#each_pairObject



1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
# File 'lib/test/unit/assertions.rb', line 1913

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

#inspectObject



1890
1891
1892
# File 'lib/test/unit/assertions.rb', line 1890

def inspect
  @hash.inspect
end

#pretty_print(q) ⇒ Object



1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
# File 'lib/test/unit/assertions.rb', line 1894

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



1909
1910
1911
# File 'lib/test/unit/assertions.rb', line 1909

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