Module: Protest::Utils::Summaries

Overview

Mixin that provides summaries for your text based test runs.

Instance Method Summary collapse

Instance Method Details

#summarize_errorsObject

Call on :end to print a list of failures (failed assertions) and errors (unrescued exceptions), including file and line number where the test failed, and a short backtrace.

It will not output anything if there weren’t any failures or errors.

For example:

on :end do |report|
  report.puts
  report.summarize_errors
end

This relies on the public Report API, and on the presence of a #puts method to write to whatever source you are writing your report.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/protest/utils/summaries.rb', line 65

def summarize_errors
  return if failures_and_errors.empty?

  puts "Failures:"
  puts

  pad_indexes = failures_and_errors.size.to_s.size
  failures_and_errors.each_with_index do |error, index|
    colorize_as = ErroredTest === error ? :errored : :failed
    puts "  #{pad(index+1, pad_indexes)}) #{test_type(error)}: `#{error.test_name}' (on line #{error.line} of `#{error.file}')", colorize_as
    puts indent("With `#{error.error_message}'", 6 + pad_indexes), colorize_as
    indent(error.backtrace[0..2], 6 + pad_indexes).each {|backtrace| puts backtrace, colorize_as }
    puts
  end
end

#summarize_pending_testsObject

Call on :end to print a list of pending tests, including file and line number where the call to TestCase#pending+ was made.

It will not output anything if there weren’t any pending tests.

For example:

on :end do |report|
  report.puts
  report.summarize_pending_tests
end

This relies on the public Report API, and on the presence of a #puts method to write to whatever source you are writing your report.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/protest/utils/summaries.rb', line 36

def summarize_pending_tests
  return if pendings.empty?

  puts "Pending tests:"
  puts

  pad_indexes = pendings.size.to_s.size
  pendings.each_with_index do |pending, index|
    puts "  #{pad(index+1, pad_indexes)}) #{pending.test_name} (#{pending.pending_message})", :pending
    puts indent("On line #{pending.line} of `#{pending.file}'", 6 + pad_indexes), :pending
    puts
  end
end

#summarize_test_totalsObject

Call on :end to output the amount of tests (passed, pending, failed and errored), the amount of assertions, and the time elapsed.

For example:

on :end do |report|
  report.puts
  report.summarize_test_totals
end

This relies on the public Report API, and on the presence of a #puts method to write to whatever source you are writing your report.



17
18
19
20
# File 'lib/protest/utils/summaries.rb', line 17

def summarize_test_totals
  puts test_totals
  puts running_time
end