Module: Protest::Utils::Summaries

Included in:
Report
Defined in:
lib/protest/utils/summaries.rb

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 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
80
81
82
83
84
85
86
87
88
# 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|
    if ErroredTest === error
      colorize_as = :errored
      error_prefix = "With #{error.error.class.name}:"
    else
      colorize_as = :failed
      error_prefix = "With"
    end

    lines = []
    lines << "  #{pad(index+1, pad_indexes)}) #{test_type(error)}: `#{error.test_name}' (on line #{error.line} of `#{error.file}')"
    lines.concat indent("#{error_prefix} `#{error.error_message}'", 6 + pad_indexes)
    lines.concat indent(error.backtrace, 6 + pad_indexes)
    lines.each { |line| puts line, 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