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.



2098
2099
2100
2101
2102
2103
2104
2105
2106
# File 'lib/test/unit/assertions.rb', line 2098

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)


2093
2094
2095
# File 'lib/test/unit/assertions.rb', line 2093

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

Instance Method Details

#each_pairObject



2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
# File 'lib/test/unit/assertions.rb', line 2131

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



2108
2109
2110
# File 'lib/test/unit/assertions.rb', line 2108

def inspect
  @hash.inspect
end

#pretty_print(q) ⇒ Object



2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
# File 'lib/test/unit/assertions.rb', line 2112

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



2127
2128
2129
# File 'lib/test/unit/assertions.rb', line 2127

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