Module: Spinach::Reporter::Stdout::ErrorReporting
- Included in:
- Spinach::Reporter::Stdout
- Defined in:
- lib/spinach/reporter/stdout/error_reporting.rb
Overview
This module handles Stdoutās reporter error reporting capabilities.
Instance Method Summary collapse
-
#error_summary ⇒ Object
Prints the errors for this run.
-
#full_error(error) ⇒ String
Returns a complete error report.
-
#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
-
#summarized_error(error) ⇒ String
Returns summarized error report.
Instance Method Details
#error_summary ⇒ Object
Prints the errors for this run.
9 10 11 12 13 14 15 16 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 9 def error_summary error.puts "\nError summary:\n" report_error_steps report_failed_steps report_undefined_features report_undefined_steps report_pending_steps end |
#full_error(error) ⇒ String
Returns a complete error report
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/spinach/reporter/stdout/error_reporting.rb', line 114 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".yellow suggestion = Generators::StepGenerator.new(step).generate suggestion.split("\n").each do |line| output << " #{line}\n".yellow 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 |
#report_error(error, format = :summarized) ⇒ String
Prints an error in a nice format
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 74 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
18 19 20 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 18 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
54 55 56 57 58 59 60 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 54 def report_errors(, steps, color) error.puts " #{banner} (#{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.
153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 153 def report_exception(exception) output = exception..split("\n").map{ |line| " #{line}" }.join("\n") if exception.kind_of?(Spinach::StepNotDefinedException) output.yellow elsif exception.kind_of?(Spinach::StepPendingException) output.yellow else output.red end end |
#report_failed_steps ⇒ Object
22 23 24 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 22 def report_failed_steps report_errors('Failures', failed_steps, :light_red) if failed_steps.any? end |
#report_pending_steps ⇒ Object
30 31 32 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 30 def report_pending_steps report_errors('Pending steps', pending_steps, :yellow) if pending_steps.any? end |
#report_undefined_features ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 34 def report_undefined_features if undefined_features.any? error.puts " Undefined features (#{undefined_features.length})".light_yellow undefined_features.each do |feature| error.puts " #{feature.name}".yellow end end end |
#report_undefined_steps ⇒ Object
26 27 28 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 26 def report_undefined_steps report_errors('Undefined steps', undefined_steps, :yellow) if undefined_steps.any? end |
#summarized_error(error) ⇒ String
Returns summarized error report
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 93 def summarized_error(error) feature, scenario, step, exception = error summary = " #{feature.name} :: #{scenario.name} :: #{full_step step}" if exception.kind_of?(Spinach::StepNotDefinedException) summary.yellow elsif exception.kind_of?(Spinach::StepPendingException) summary += "\n Reason: '#{exception.reason}'\n" summary.yellow else summary.red end end |