Class: Test::Reporters::Outline

Inherits:
Dotprogress show all
Defined in:
lib/rubytest/format/outline.rb

Overview

Nest case headings and show each result at its place in the suite.

Constant Summary collapse

SYMBOLS =
{
  pass: '.', fail: 'F', error: 'E', todo: 'P', skip: 'S'
}.freeze

Instance Attribute Summary

Attributes inherited from Abstract

#runner

Instance Method Summary collapse

Methods inherited from Dotprogress

#error, #fail, #finish, #initialize, #pass, #skip_case, #skip_test, #todo

Methods inherited from Abstract

#begin_test, #end_test, inherited, #initialize, registry

Constructor Details

This class inherits a constructor from Test::Reporters::Dotprogress

Instance Method Details

#begin_case(test_case) ⇒ Object



14
15
16
17
# File 'lib/rubytest/format/outline.rb', line 14

def begin_case(test_case)
  @output.puts "#{'  ' * @depth}#{test_case.to_s.lines.first.to_s.strip}"
  @depth += 1
end

#begin_suite(suite) ⇒ Object



10
11
12
# File 'lib/rubytest/format/outline.rb', line 10

def begin_suite(suite)
  @depth = 0
end

#end_case(test_case) ⇒ Object



19
20
21
# File 'lib/rubytest/format/outline.rb', line 19

def end_case(test_case)
  @depth -= 1
end

#end_suite(suite) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/rubytest/format/outline.rb', line 36

def end_suite(suite)
  summary = @summary
  @output.puts
  rate = summary.elapsed.zero? ? 0.0 : summary.total / summary.elapsed
  @output.puts "Finished in %.5fs, %.2f tests/s." % [summary.elapsed, rate]
  @output.puts summary.total.zero? ? 'No tests were run.' : tally_for(summary)
end

#record(result) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubytest/format/outline.rb', line 23

def record(result)
  depth = result.kind == :case && @depth.positive? ? @depth - 1 : @depth
  indent = '  ' * depth
  @output.puts "#{indent}#{SYMBOLS.fetch(result.status)} #{result.test.to_s.lines.first.to_s.strip}"
  if [:fail, :error].include?(result.status)
    result.exceptions.each do |exception|
      @output.puts "#{indent}  #{exception.class}: #{exception.message}"
      location = file_and_line(exception)
      @output.puts "#{indent}  #{location}" unless location.empty?
    end
  end
end