Module: Spinach::Reporter::Reporting
Overview
This module handles Stdoutās reporter error reporting capabilities.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
The output buffers to store the reports.
-
#out ⇒ Object
readonly
The output buffers to store the reports.
-
#scenario ⇒ Object
The last scenario.
-
#scenario_error ⇒ Object
The last scenario error.
Instance Method Summary collapse
-
#after_run(success) ⇒ Object
It prints the error summary if the run has failed It always print feature success summary.
- #before_run ⇒ Object
-
#error_summary ⇒ Object
Prints the errors for this run.
- #format_summary(color, steps, message) ⇒ Object
-
#full_error(error) ⇒ String
Returns a complete error report.
-
#full_step(step) ⇒ Object
Constructs the full step definition.
-
#report_error(error, format = :summarized) ⇒ String
Prints an error in a nice format.
- #report_error_steps ⇒ Object
-
#report_errors(banner, steps, color) ⇒ Object
Prints the error for a given set of steps.
-
#report_exception(exception) ⇒ String
Prints a information when an exception is raised.
- #report_failed_steps ⇒ Object
- #report_pending_steps ⇒ Object
- #report_undefined_features ⇒ Object
- #report_undefined_steps ⇒ Object
-
#run_summary ⇒ Object
Prints the feature success summary for this run.
-
#summarized_error(error) ⇒ String
Returns summarized error report.
Instance Attribute Details
#error ⇒ Object (readonly)
The output buffers to store the reports.
7 8 9 |
# File 'lib/spinach/reporter/reporting.rb', line 7 def error @error end |
#out ⇒ Object (readonly)
The output buffers to store the reports.
7 8 9 |
# File 'lib/spinach/reporter/reporting.rb', line 7 def out @out end |
#scenario ⇒ Object
The last scenario
13 14 15 |
# File 'lib/spinach/reporter/reporting.rb', line 13 def scenario @scenario end |
#scenario_error ⇒ Object
The last scenario error
10 11 12 |
# File 'lib/spinach/reporter/reporting.rb', line 10 def scenario_error @scenario_error end |
Instance Method Details
#after_run(success) ⇒ Object
It prints the error summary if the run has failed It always print feature success summary
208 209 210 211 212 |
# File 'lib/spinach/reporter/reporting.rb', line 208 def after_run(success) error_summary unless success out.puts "" run_summary end |
#before_run ⇒ Object
198 199 200 |
# File 'lib/spinach/reporter/reporting.rb', line 198 def before_run(*) @start_time = Time.now end |
#error_summary ⇒ Object
Prints the errors for this run.
17 18 19 20 21 22 23 24 |
# File 'lib/spinach/reporter/reporting.rb', line 17 def error_summary error.puts "\nError summary:\n" report_error_steps report_failed_steps report_undefined_features report_undefined_steps report_pending_steps end |
#format_summary(color, steps, message) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/spinach/reporter/reporting.rb', line 189 def format_summary(color, steps, ) buffer = [] buffer << "(".colorize(color) buffer << steps.length.to_s.colorize(:"light_#{color}") buffer << ") ".colorize(color) buffer << .colorize(color) buffer.join end |
#full_error(error) ⇒ String
Returns a complete error report
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/spinach/reporter/reporting.rb', line 128 def full_error(error) feature, scenario, step, exception = error output = "\n" output += report_exception(exception) output +="\n" if exception.kind_of?(Spinach::StepNotDefinedException) output << "\n" output << " You can define it with: \n\n".red suggestion = Generators::StepGenerator.new(step).generate suggestion.split("\n").each do |line| output << " #{line}\n".red end output << "\n" elsif exception.kind_of?(Spinach::StepPendingException) output << " Reason: '#{exception.reason}'".yellow output << "\n" else if [:backtrace] output += "\n" exception.backtrace.map do |line| output << " #{line}\n" end else output << " #{exception.backtrace[0]}" end end output end |
#full_step(step) ⇒ Object
Constructs the full step definition
185 186 187 |
# File 'lib/spinach/reporter/reporting.rb', line 185 def full_step(step) "#{step.keyword} #{step.name}" end |
#report_error(error, format = :summarized) ⇒ String
Prints an error in a nice format
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/spinach/reporter/reporting.rb', line 88 def report_error(error, format=:summarized) case format when :summarized self.error.puts summarized_error(error) when :full self.error.puts full_error(error) else raise "Format not defined" end end |
#report_error_steps ⇒ Object
26 27 28 |
# File 'lib/spinach/reporter/reporting.rb', line 26 def report_error_steps report_errors('Errors', error_steps, :light_red) if error_steps.any? end |
#report_errors(banner, steps, color) ⇒ Object
Prints the error for a given set of steps
68 69 70 71 72 73 74 |
# File 'lib/spinach/reporter/reporting.rb', line 68 def report_errors(, steps, color) error.puts " #{} (#{steps.length})".colorize(color) steps.each do |error| report_error error end error.puts "" end |
#report_exception(exception) ⇒ String
Prints a information when an exception is raised.
166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/spinach/reporter/reporting.rb', line 166 def report_exception(exception) output = exception..split("\n").map{ |line| " #{line}" }.join("\n") if exception.kind_of?(Spinach::StepNotDefinedException) output.red elsif exception.kind_of?(Spinach::StepPendingException) output.yellow else output.red end end |
#report_failed_steps ⇒ Object
30 31 32 |
# File 'lib/spinach/reporter/reporting.rb', line 30 def report_failed_steps report_errors('Failures', failed_steps, :light_red) if failed_steps.any? end |
#report_pending_steps ⇒ Object
41 42 43 44 45 46 |
# File 'lib/spinach/reporter/reporting.rb', line 41 def report_pending_steps if pending_steps.any? error.puts "\nPending steps summary:\n" report_errors('Pending steps', pending_steps, :yellow) end end |
#report_undefined_features ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/spinach/reporter/reporting.rb', line 48 def report_undefined_features if undefined_features.any? error.puts " Undefined features (#{undefined_features.length})".red undefined_features.each do |feature| error.puts " #{feature.name}".red end end end |
#report_undefined_steps ⇒ Object
34 35 36 37 38 39 |
# File 'lib/spinach/reporter/reporting.rb', line 34 def report_undefined_steps if undefined_steps.any? error.puts "\nUndefined steps summary:\n" report_errors('Undefined steps', undefined_steps, :red) end end |
#run_summary ⇒ Object
Prints the feature success summary for this run.
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/spinach/reporter/reporting.rb', line 216 def run_summary successful_summary = format_summary(:green, successful_steps, 'Successful') undefined_summary = format_summary(:red, undefined_steps, 'Undefined') pending_summary = format_summary(:yellow, pending_steps, 'Pending') failed_summary = format_summary(:red, failed_steps, 'Failed') error_summary = format_summary(:red, error_steps, 'Error') out.puts "Steps Summary: #{successful_summary}, #{pending_summary}, #{undefined_summary}, #{failed_summary}, #{error_summary}\n\n" out.puts "Finished in #{Time.now - @start_time} seconds\n\n" if @start_time @orderer.attach_summary(out) if @orderer end |
#summarized_error(error) ⇒ String
Returns summarized error report
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/spinach/reporter/reporting.rb', line 107 def summarized_error(error) feature, scenario, step, exception = error summary = " #{feature.name} :: #{scenario.name} :: #{full_step step}" if exception.kind_of?(Spinach::StepNotDefinedException) summary.red elsif exception.kind_of?(Spinach::StepPendingException) summary += "\n Reason: '#{exception.reason}'\n" summary.yellow else summary.red end end |