Class: MiniTest::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/minitest/display.rb

Instance Method Summary collapse

Instance Method Details

#_run_anything(type) ⇒ Object

Monkey Patchin!



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/minitest/display.rb', line 120

def _run_anything(type)
  suites = TestCase.send "#{type}_suites"
  return if suites.empty?

  start = Time.now

  puts
  puts "# Running #{type}s:"
  puts

  @test_count, @assertion_count = 0, 0
  sync = output.respond_to? :"sync=" # stupid emacs
  old_sync, output.sync = output.sync, true if sync

  results = _run_suites suites, type

  @test_count      = results.inject(0) { |sum, (tc, _)| sum + tc }
  @assertion_count = results.inject(0) { |sum, (_, ac)| sum + ac }

  output.sync = old_sync if sync

  t = Time.now - start

  puts
  puts
  puts "Finished #{type}s in %.6fs, %.4f tests/s, %.4f assertions/s." %
    [t, test_count / t, assertion_count / t]

  report.each_with_index do |msg, i|
    puts "\n%3d) %s" % [i + 1, msg]
  end

  puts

  status
end

#_run_suite(suite, type) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/minitest/display.rb', line 157

def _run_suite(suite, type)
  suite_header = ""
  if display.options[:suite_names] && display.printable_suite?(suite)
    suite_header = suite.to_s
    print display.color("\n#{suite_header}#{display.options[:suite_divider]}", :suite)
  end

  filter = options[:filter] || '/./'
  filter = Regexp.new $1 if filter =~ /\/(.*)\//

  wrap_at = display.options[:wrap_at] - suite_header.length
  wrap_count = wrap_at

  full_start_time = Time.now
  @test_times ||= []
  assertions = suite.send("#{type}_methods").grep(filter).map { |method|
    inst = suite.new method
    inst._assertions = 0

    print "#{suite}##{method} = " if @verbose

    @start_time = Time.now
    result = inst.run self
    time = Time.now - @start_time

    @test_times << ["#{suite}##{method}", time]

    print "%.2f s = " % time if @verbose
    print case result
    when "."
      display.color(display.options[:print][:success], :success)
    when "F"
      display.color(display.options[:print][:failure], :failure)
    when "E"
      display.color(display.options[:print][:error], :error)
    else
      result
    end
    puts if @verbose

    wrap_count -= 1
    if wrap_count == 0
      print "\n#{' ' * suite_header.length}#{display.options[:suite_divider]}"
      wrap_count = wrap_at
    end

    inst._assertions
  }

  total_time = Time.now - full_start_time

  if assertions.length > 0 && display.options[:suite_time]
    print "\n#{' ' * suite_header.length}#{display.options[:suite_divider]}"
    print "%.2f s" % total_time
  end
  return assertions.size, assertions.inject(0) { |sum, n| sum + n }
end

#status(io = self.output) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/minitest/display.rb', line 215

def status(io = self.output)
  format = "%d tests, %d assertions, %d failures, %d errors, %d skips"
  final_status = failures + errors > 0 ? :failure : :success
  io.puts display.color(format % [test_count, assertion_count, failures, errors, skips], [:bold, final_status])

  if display.options[:output_slow]
    @test_times.sort! {|a, b| b[1] <=> a[1] }
    puts "Slowest tests:"
    @test_times[0..display.options[:output_slow].to_i].each do |test_name, time|
      puts "%.2f s\t#{test_name}" % time
    end
  end
end