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
Prints the steps that raised an error.
-
#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
Prints failing steps.
- #report_undefined_features ⇒ Object
-
#report_undefined_steps ⇒ Object
Prints undefined steps.
-
#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 |
# 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 end |
#full_error(error) ⇒ String
Returns a complete error report
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 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 112 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" 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
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 75 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
Prints the steps that raised an error.
19 20 21 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 19 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
55 56 57 58 59 60 61 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 55 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.
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 148 def report_exception(exception) output = exception..split("\n").map{ |line| " #{line}" }.join("\n") if exception.kind_of?(Spinach::StepNotDefinedException) output.yellow else output.red end end |
#report_failed_steps ⇒ Object
Prints failing steps.
25 26 27 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 25 def report_failed_steps report_errors('Failures', failed_steps, :light_red) if failed_steps.any? end |
#report_undefined_features ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 35 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
Prints undefined steps.
31 32 33 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 31 def report_undefined_steps report_errors('Undefined steps', undefined_steps, :yellow) if undefined_steps.any? end |
#summarized_error(error) ⇒ String
Returns summarized error report
94 95 96 97 98 99 100 101 102 |
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 94 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 else summary.red end end |