Module: Spinach::Reporter::ErrorReporting
- Included in:
- Console
- Defined in:
- lib/spinach-console-reporter/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.
8 9 10 11 12 13 14 15 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 8 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
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 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 113 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 << yellow(" Reason: '#{exception.reason}'") 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
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 73 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
17 18 19 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 17 def report_error_steps report_errors('Errors', error_steps, :red) if error_steps.any? end |
#report_errors(banner, steps, color) ⇒ Object
Prints the error for a given set of steps
53 54 55 56 57 58 59 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 53 def report_errors(, steps, color) error.puts send(color, " #{} (#{steps.length})") steps.each do |error| report_error error end error.puts "" end |
#report_exception(exception) ⇒ String
Prints a information when an exception is raised.
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 152 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
21 22 23 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 21 def report_failed_steps report_errors('Failures', failed_steps, :red) if failed_steps.any? end |
#report_pending_steps ⇒ Object
29 30 31 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 29 def report_pending_steps report_errors('Pending steps', pending_steps, :yellow) if pending_steps.any? end |
#report_undefined_features ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 33 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
25 26 27 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 25 def report_undefined_steps report_errors('Undefined steps', undefined_steps, :yellow) if undefined_steps.any? end |
#summarized_error(error) ⇒ String
Returns summarized error report
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/spinach-console-reporter/error_reporting.rb', line 92 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" yellow(summary) else red(summary) end end |