Class: Test::Reporters::Dotprogress

Inherits:
Abstract
  • Object
show all
Defined in:
lib/rubytest/format/dotprogress.rb

Overview

Simple Dot-Progress Reporter

Direct Known Subclasses

Outline, Progress, Summary

Instance Attribute Summary

Attributes inherited from Abstract

#runner

Instance Method Summary collapse

Methods inherited from Abstract

#begin_case, #begin_suite, #begin_test, #end_case, #end_test, inherited, registry

Constructor Details

#initialize(runner, output: $stdout) ⇒ Dotprogress

Returns a new instance of Dotprogress.



8
9
10
11
12
# File 'lib/rubytest/format/dotprogress.rb', line 8

def initialize(runner, output: $stdout)
  super(runner)
  @output = output
  @verbose = runner.verbose?
end

Instance Method Details

#end_suite(suite) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
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
92
# File 'lib/rubytest/format/dotprogress.rb', line 54

def end_suite(suite)
  summary = @summary
  @output.puts
  @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

  if @verbose && summary.counts[:skip].positive?
    @output.puts "SKIPPED\n\n"
    summary.results_for(:skip).each do |result|
      @output.puts "    #{result.test}".ansi(:bold)
      @output.puts "    #{result.reason}" if String === result.reason
      @output.puts
    end
  end

  {todo: 'PENDING', fail: 'FAILURES', error: 'ERRORS'}.each do |status, title|
    next if summary.counts[status].zero?
    @output.puts "#{title}\n\n"
    summary.results_for(status).each do |result|
      @output.puts "    #{result.test}".ansi(:bold) unless status == :todo && result.test.to_s.empty?
      result.exceptions.each_with_index do |exception, index|
        prefix = result.exceptions.size > 1 ? "#{index + 1}. " : ''
        @output.puts "    #{prefix}#{exception.class}: #{exception.message}"
        @output.puts "    #{file_and_line(exception)}"
        @output.puts code(exception)
        @output.puts "    " + clean_backtrace(exception).join("\n    ") unless status == :todo
      end
      @output.puts
    end
  end

  if summary.total.zero?
    @output.puts 'No tests were run.'
  else
    @output.puts tally_for(summary)
  end
end

#error(test, exception) ⇒ Object



46
47
48
# File 'lib/rubytest/format/dotprogress.rb', line 46

def error(test, exception)
  emit('E'.ansi(:red, :bold))
end

#fail(test, exception) ⇒ Object



42
43
44
# File 'lib/rubytest/format/dotprogress.rb', line 42

def fail(test, exception)
  emit('F'.ansi(:red))
end

#finish(summary) ⇒ Object



25
26
27
28
# File 'lib/rubytest/format/dotprogress.rb', line 25

def finish(summary)
  @summary = summary
  end_suite(summary.suite)
end

#pass(test) ⇒ Object



38
39
40
# File 'lib/rubytest/format/dotprogress.rb', line 38

def pass(test)
  emit('.')
end

#record(result) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/rubytest/format/dotprogress.rb', line 14

def record(result)
  if result.status == :skip
    method = result.kind == :case ? :skip_case : :skip_test
    public_send(method, result.test, result.reason)
  elsif result.status == :pass
    pass(result.test)
  else
    public_send(result.status, result.test, result.exception)
  end
end

#skip_case(test_case, reason) ⇒ Object



34
35
36
# File 'lib/rubytest/format/dotprogress.rb', line 34

def skip_case(test_case, reason)
  emit('S'.ansi(:cyan)) if @verbose
end

#skip_test(test, reason) ⇒ Object



30
31
32
# File 'lib/rubytest/format/dotprogress.rb', line 30

def skip_test(test, reason)
  emit('S'.ansi(:cyan)) if @verbose
end

#todo(test, exception) ⇒ Object



50
51
52
# File 'lib/rubytest/format/dotprogress.rb', line 50

def todo(test, exception)
  emit('P'.ansi(:yellow))
end