Module: Protest::Utils::Summaries

Included in:
Reports::Documentation, Reports::Progress
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 short backtrace.

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.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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)} in `#{error.test.context_description} #{error.test_name}' (on line #{error.line} of `#{error.file}')", colorize_as
    # If error message has line breaks, indent the message
    prefix = "with"
    unless error.error.is_a?(Protest::AssertionFailed) ||
    ((RUBY_VERSION =~ /^1\.9/) ? error.error.is_a?(MiniTest::Assertion) : error.error.is_a?(::Test::Unit::AssertionFailedError))
      prefix << " #{error.error.class}" 
    end
    if error.error_message =~ /\n/
      puts indent("#{prefix}: <<", 6 + pad_indexes), colorize_as
      puts indent(error.error_message, 6 + pad_indexes + 2), colorize_as
      puts indent(">>", 6 + pad_indexes), colorize_as
    else
      puts indent("#{prefix} `#{error.error_message}'", 6 + pad_indexes), colorize_as
    end
    indent(error.backtrace[1..-1], 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