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.



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

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)


1907
1908
1909
# File 'lib/test/unit/assertions.rb', line 1907

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

Instance Method Details

#each_pairObject



1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
# File 'lib/test/unit/assertions.rb', line 1945

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



1922
1923
1924
# File 'lib/test/unit/assertions.rb', line 1922

def inspect
  @hash.inspect
end

#pretty_print(q) ⇒ Object



1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
# File 'lib/test/unit/assertions.rb', line 1926

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



1941
1942
1943
# File 'lib/test/unit/assertions.rb', line 1941

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