Class: Rproof::LiveReporter

Inherits:
AbstractReporter show all
Defined in:
lib/rproof/live_reporter.rb

Constant Summary collapse

OK =
'['.bold + 'OK'.green.bold + ']'.bold
KO =
'['.bold + 'KO'.red.bold + ']'.bold
WA =
'['.bold + 'W!'.yellow.bold + ']'.bold
WARNING =
'/!\\ WARNING /!\\'.yellow.bold
STATUS =
{
  untested:   'untested'.bold.on_blue,
  exception:  'exception'.bold.on_magenta,
  failed:     'failed'.bold.red,
  warning:    'succeed'.bold.green + ' with ' + 'warnings'.bold.yellow,
  succeed:    'succeed'.bold.green
}
INDENT =
"  "

Instance Method Summary collapse

Constructor Details

#initialize(verbose: false, cli_width: 80, justification: ([60, cli_width - 100].max)) ⇒ LiveReporter

Returns a new instance of LiveReporter.



28
29
30
31
# File 'lib/rproof/live_reporter.rb', line 28

def initialize(verbose: false, cli_width: 80, justification: ([60, cli_width - 100].max))
  @verbose = verbose
  @justification = justification
end

Instance Method Details

#report_assertion(assertion) ⇒ Object



52
53
54
55
56
57
58
59
60
61
# File 'lib/rproof/live_reporter.rb', line 52

def report_assertion(assertion)
  if @verbose
    if assertion.is_successful
      puts "#{INDENT}#{(assertion.comment + ' ').ljust(@justification, '_')} #{OK} obtained #{assertion.obtained.inspect}"
    else
      puts "#{INDENT}#{(assertion.comment + ' ').ljust(@justification, '_')} #{KO} expected #{assertion.expected.inspect}"
      puts "#{INDENT}#{' ' * @justification}      obtained #{assertion.obtained.inspect}"
    end
  end
end

#report_campaign_beginObject



33
34
35
36
37
# File 'lib/rproof/live_reporter.rb', line 33

def report_campaign_begin
  if @verbose
    puts "Running test campaign..."
  end
end

#report_campaign_end(test_results, start_time, end_time) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/rproof/live_reporter.rb', line 94

def report_campaign_end(test_results, start_time, end_time)
  if test_results.is_a? Array # if false, campaign was a single test
    campaign_status = :succeed
    successes_nb = 0
    failures_nb = 0
    warnings_nb = 0
    exceptions_nb = 0

    results = test_results.flatten
    results.each do |result|
      campaign_status = TestResult.get_worse_status campaign_status, result.status
      successes_nb += result.successes_nb
      failures_nb += result.failures_nb
      warnings_nb += result.warnings.count
      exceptions_nb += result.exceptions.count
    end
    if @verbose
      puts
      puts "End of campaign: #{STATUS[campaign_status]}. #{successes_nb} successes, #{failures_nb} failures, #{warnings_nb} warnings, #{exceptions_nb} exceptions"
    else
      puts
      puts "#{STATUS[campaign_status]} in #{end_time - start_time}. #{successes_nb} successes, #{failures_nb} failures, #{warnings_nb} warnings, #{exceptions_nb} exceptions"
      if warnings_nb > 0
        puts
        puts " warnings:"
        results.each do |result|
          result.warnings.each do |warning|
            full_comment = "in #{warning.file}:#{warning.line}:#{warning.method}: #{warning.message} "
            puts "  #{full_comment.ljust(@justification, '_')} #{WA}"
          end
        end
      end
      if failures_nb > 0
        puts
        puts " failures:"
        results.each do |result|
          result.failures.each do |failure|
            full_comment = "in #{failure.file}:#{failure.line}:#{failure.method}: #{failure.comment} "
            puts "  #{full_comment.ljust(@justification, '_')} #{KO} #{"expected".bold} #{failure.expected.inspect}, #{"obtained".bold} #{failure.obtained.inspect}"
          end
        end
      end
      if exceptions_nb > 0
        print_header('exceptions')
        print_exceptions(results)
      end
    end
  end
end

#report_exception(exception) ⇒ Object



69
70
71
72
73
74
# File 'lib/rproof/live_reporter.rb', line 69

def report_exception(exception)
  if @verbose
    puts "#{INDENT}exception: " + exception.message.bold.on_magenta
    puts INDENT + exception.backtrace.join("\n#{INDENT}").bold.magenta
  end
end

#report_suite_begin(id, name, description) ⇒ Object



39
40
# File 'lib/rproof/live_reporter.rb', line 39

def report_suite_begin(id, name, description)
end

#report_suite_end(id, test_results) ⇒ Object



91
92
# File 'lib/rproof/live_reporter.rb', line 91

def report_suite_end(id, test_results)
end

#report_test_begin(id, name, description) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/rproof/live_reporter.rb', line 42

def report_test_begin(id, name, description)
  if @verbose
    puts
    puts '-' * 120
    puts "Running #{name}"
    puts description
    puts
  end
end

#report_test_end(id, test_result) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/rproof/live_reporter.rb', line 76

def report_test_end(id, test_result)
  if @verbose
    puts
    puts "End: #{STATUS[test_result.status]}. #{test_result.successes_nb} successes, #{test_result.failures_nb} failures, #{test_result.warnings.count} warnings, #{test_result.exceptions.count} exceptions"
  else
    case
    when !test_result.exceptions.empty? then dot = "E".bold.on_magenta
    when !test_result.failures.empty? then dot = "F".bold.red
    when !test_result.warnings.empty? then dot = "W".bold.yellow
    else dot = "."
    end
    print dot
  end
end

#report_warning(warning) ⇒ Object



63
64
65
66
67
# File 'lib/rproof/live_reporter.rb', line 63

def report_warning(warning)
  if @verbose
    puts "#{INDENT}#{WARNING} #{warning.message}"
  end
end