Class: Spinach::Reporter::Stdout
- Inherits:
-
Spinach::Reporter
- Object
- Spinach::Reporter
- Spinach::Reporter::Stdout
- Defined in:
- lib/spinach/reporter/stdout.rb
Overview
The Stdout reporter outputs the runner results to the standard output
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_error ⇒ Object
The last scenario error.
Attributes inherited from Spinach::Reporter
#current_feature, #current_scenario, #error_steps, #failed_steps, #options, #undefined_features, #undefined_steps
Instance Method Summary collapse
-
#after_run(success) ⇒ Object
It prints the error summary if the run has failed.
-
#after_scenario_run(data) ⇒ Object
Adds an error report and re.
-
#before_feature_run(data) ⇒ Object
Prints the feature name to the standard output.
-
#before_scenario_run(data) ⇒ Object
Prints the scenario name to the standard ouput.
-
#error_summary ⇒ Object
Prints the errors for ths run.
-
#full_error(error) ⇒ Object
Returns a complete error report.
-
#full_step(step) ⇒ Object
Constructs the full step definition.
-
#initialize(*args) ⇒ Stdout
constructor
Initialitzes the runner.
-
#on_error_step(step, failure, step_location) ⇒ Object
Adds a step that has raised an error to the output buffer.
-
#on_failed_step(step, failure, step_location) ⇒ Object
Adds a failing step to the output buffer.
-
#on_feature_not_found(feature, exception) ⇒ Object
Adds a feature not found message to the output buffer.
-
#on_skipped_step(step) ⇒ Object
Adds a step that has been skipped to the output buffer.
-
#on_successful_step(step, step_location) ⇒ Object
Adds a passed step to the output buffer.
-
#on_undefined_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
-
#output_step(symbol, step, color, step_location = nil) ⇒ Object
Adds to the output buffer a step result.
-
#report_error(error, format = :summarized) ⇒ Object
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) ⇒ Object
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) ⇒ Object
Returns summarized error report.
Methods inherited from Spinach::Reporter
#after_feature_run, #bind, #clear_current_feature, #clear_current_scenario, #feature_runner, #runner, #scenario_runner
Constructor Details
#initialize(*args) ⇒ Stdout
Initialitzes the runner
21 22 23 24 25 26 |
# File 'lib/spinach/reporter/stdout.rb', line 21 def initialize(*args) super(*args) @out = [:output] || $stdout @error = [:error] || $stderr @max_step_name_length = 0 end |
Instance Attribute Details
#error ⇒ Object (readonly)
The output buffers to store the reports.
10 11 12 |
# File 'lib/spinach/reporter/stdout.rb', line 10 def error @error end |
#out ⇒ Object (readonly)
The output buffers to store the reports.
10 11 12 |
# File 'lib/spinach/reporter/stdout.rb', line 10 def out @out end |
#scenario_error ⇒ Object
The last scenario error
13 14 15 |
# File 'lib/spinach/reporter/stdout.rb', line 13 def scenario_error @scenario_error end |
Instance Method Details
#after_run(success) ⇒ Object
It prints the error summary if the run has failed
174 175 176 |
# File 'lib/spinach/reporter/stdout.rb', line 174 def after_run(success) error_summary unless success end |
#after_scenario_run(data) ⇒ Object
Adds an error report and re
54 55 56 57 58 59 |
# File 'lib/spinach/reporter/stdout.rb', line 54 def after_scenario_run(data) if scenario_error report_error(scenario_error, :full) self.scenario_error = nil end end |
#before_feature_run(data) ⇒ Object
Prints the feature name to the standard output
33 34 35 36 |
# File 'lib/spinach/reporter/stdout.rb', line 33 def before_feature_run(data) name = data['name'] out.puts "\n#{'Feature:'.magenta} #{name.light_magenta}" end |
#before_scenario_run(data) ⇒ Object
Prints the scenario name to the standard ouput
43 44 45 46 47 |
# File 'lib/spinach/reporter/stdout.rb', line 43 def before_scenario_run(data) @max_step_name_length = data['steps'].map{|step| step['name'].length}.max if data['steps'] name = data['name'] out.puts "\n #{'Scenario:'.green} #{name.light_green}" end |
#error_summary ⇒ Object
Prints the errors for ths run.
180 181 182 183 184 185 186 |
# File 'lib/spinach/reporter/stdout.rb', line 180 def error_summary error.puts "\nError summary:\n" report_error_steps report_failed_steps report_undefined_features report_undefined_steps end |
#full_error(error) ⇒ Object
Returns a complete error report
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/spinach/reporter/stdout.rb', line 283 def full_error(error) feature, scenario, step, exception = error output = String.new output += report_exception(exception) output +="\n" if [:backtrace] output += "\n" exception.backtrace.map do |line| output << " #{line}\n" end else output << " #{exception.backtrace[0]}" end output end |
#full_step(step) ⇒ Object
Constructs the full step definition
305 306 307 |
# File 'lib/spinach/reporter/stdout.rb', line 305 def full_step(step) "#{step['keyword'].strip} #{step['name'].strip}" end |
#on_error_step(step, failure, step_location) ⇒ Object
Adds a step that has raised an error to the output buffer.
92 93 94 95 96 |
# File 'lib/spinach/reporter/stdout.rb', line 92 def on_error_step(step, failure, step_location) output_step('!', step, :red, step_location) self.scenario_error = [current_feature, current_scenario, step, failure] error_steps << scenario_error end |
#on_failed_step(step, failure, step_location) ⇒ Object
Adds a failing step to the output buffer.
78 79 80 81 82 |
# File 'lib/spinach/reporter/stdout.rb', line 78 def on_failed_step(step, failure, step_location) output_step('✘', step, :red, step_location) self.scenario_error = [current_feature, current_scenario, step, failure] failed_steps << scenario_error end |
#on_feature_not_found(feature, exception) ⇒ Object
Adds a feature not found message to the output buffer.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/spinach/reporter/stdout.rb', line 117 def on_feature_not_found(feature, exception) lines = "#{exception.}\n" lines << "\nPlease create the file #{Spinach::Support.underscore(exception.missing_class)}.rb at #{Spinach.config[:step_definitions_path]}, with:\n\n" lines << "Feature '#{feature['name']}' do\n" # TODO: Write the actual steps. We can do this since we have the entire # feature just here. We should iterate over all the scenarios and return # the different steps # lines << " # Write your steps here" lines << "end\n\n" lines.split("\n").each do |line| out.puts " #{line}".yellow end undefined_features << feature end |
#on_skipped_step(step) ⇒ Object
Adds a step that has been skipped to the output buffer.
143 144 145 |
# File 'lib/spinach/reporter/stdout.rb', line 143 def on_skipped_step(step) output_step('~', step, :cyan) end |
#on_successful_step(step, step_location) ⇒ Object
Adds a passed step to the output buffer.
66 67 68 |
# File 'lib/spinach/reporter/stdout.rb', line 66 def on_successful_step(step, step_location) output_step('✔', step, :green, step_location) end |
#on_undefined_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
103 104 105 106 107 |
# File 'lib/spinach/reporter/stdout.rb', line 103 def on_undefined_step(step, failure) output_step('?', step, :yellow) self.scenario_error = [current_feature, current_scenario, step] undefined_steps << scenario_error end |
#output_step(symbol, step, color, step_location = nil) ⇒ Object
Adds to the output buffer a step result
162 163 164 165 166 167 |
# File 'lib/spinach/reporter/stdout.rb', line 162 def output_step(symbol, step, color, step_location = nil) step_location = step_location.first.gsub("#{File.('.')}/", '# ')+":#{step_location.last.to_s}" if step_location max_length = @max_step_name_length + 60 # Colorize and output format correction # REMEMBER TO CORRECT PREVIOUS MAX LENGTH IF OUTPUT FORMAT IS MODIFIED out.puts " #{symbol.colorize(:"light_#{color}")} #{step['keyword'].strip.colorize(:"light_#{color}")} #{step['name'].strip.colorize(color)} ".ljust(max_length) + step_location.to_s.colorize(:grey) end |
#report_error(error, format = :summarized) ⇒ Object
Prints an error in a nice format
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/spinach/reporter/stdout.rb', line 246 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.
190 191 192 |
# File 'lib/spinach/reporter/stdout.rb', line 190 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
226 227 228 229 230 231 232 |
# File 'lib/spinach/reporter/stdout.rb', line 226 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) ⇒ Object
Prints a information when an exception is raised.
317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/spinach/reporter/stdout.rb', line 317 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.
196 197 198 |
# File 'lib/spinach/reporter/stdout.rb', line 196 def report_failed_steps report_errors('Failures', failed_steps, :light_red) if failed_steps.any? end |
#report_undefined_features ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/spinach/reporter/stdout.rb', line 206 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.
202 203 204 |
# File 'lib/spinach/reporter/stdout.rb', line 202 def report_undefined_steps report_errors('Undefined steps', undefined_steps, :yellow) if undefined_steps.any? end |
#summarized_error(error) ⇒ Object
Returns summarized error report
265 266 267 268 269 270 271 272 273 |
# File 'lib/spinach/reporter/stdout.rb', line 265 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 |