Class: Spinach::Reporter::Stdout
- Inherits:
-
Spinach::Reporter
- Object
- Spinach::Reporter
- Spinach::Reporter::Stdout
- Includes:
- ErrorReporting
- Defined in:
- lib/spinach/reporter/stdout.rb,
lib/spinach/reporter/stdout/error_reporting.rb
Overview
The Stdout reporter outputs the runner results to the standard output
Defined Under Namespace
Modules: ErrorReporting
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.
Attributes inherited from Spinach::Reporter
#current_feature, #current_scenario, #error_steps, #failed_steps, #options, #successful_steps, #undefined_features, #undefined_steps
Instance Method Summary collapse
-
#after_run(success) ⇒ Object
It prints the error summary if the run has failed It always print feature success summary.
-
#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.
-
#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) ⇒ 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.
-
#run_summary ⇒ Object
Prints the feature success summary for this run.
Methods included from ErrorReporting
#error_summary, #full_error, #report_error, #report_error_steps, #report_errors, #report_exception, #report_failed_steps, #report_undefined_features, #report_undefined_steps, #summarized_error
Methods inherited from Spinach::Reporter
#after_feature_run, #bind, #clear_current_feature, #clear_current_scenario, #set_current_feature, #set_current_scenario
Constructor Details
#initialize(*args) ⇒ Stdout
Initialitzes the runner
27 28 29 30 31 32 |
# File 'lib/spinach/reporter/stdout.rb', line 27 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.
13 14 15 |
# File 'lib/spinach/reporter/stdout.rb', line 13 def error @error end |
#out ⇒ Object (readonly)
The output buffers to store the reports.
13 14 15 |
# File 'lib/spinach/reporter/stdout.rb', line 13 def out @out end |
#scenario ⇒ Object
The last scenario
19 20 21 |
# File 'lib/spinach/reporter/stdout.rb', line 19 def scenario @scenario end |
#scenario_error ⇒ Object
The last scenario error
16 17 18 |
# File 'lib/spinach/reporter/stdout.rb', line 16 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
180 181 182 183 184 |
# File 'lib/spinach/reporter/stdout.rb', line 180 def after_run(success) error_summary unless success out.puts "" run_summary end |
#after_scenario_run(data) ⇒ Object
Adds an error report and re
60 61 62 63 64 65 |
# File 'lib/spinach/reporter/stdout.rb', line 60 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
39 40 41 42 |
# File 'lib/spinach/reporter/stdout.rb', line 39 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
49 50 51 52 53 |
# File 'lib/spinach/reporter/stdout.rb', line 49 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 |
#full_step(step) ⇒ Object
Constructs the full step definition
201 202 203 |
# File 'lib/spinach/reporter/stdout.rb', line 201 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.
103 104 105 106 107 |
# File 'lib/spinach/reporter/stdout.rb', line 103 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.
89 90 91 92 93 |
# File 'lib/spinach/reporter/stdout.rb', line 89 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) ⇒ Object
Adds a feature not found message to the output buffer.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/spinach/reporter/stdout.rb', line 128 def on_feature_not_found(feature) generator = Generators::FeatureGenerator.new(feature) lines = "Could not find steps for `#{feature['name']}` feature\n\n" lines << "\nPlease create the file #{generator.filename} at #{generator.path}, with:\n\n" lines << generator.generate lines.split("\n").each do |line| out.puts " #{line}".yellow end out.puts "\n\n" undefined_features << feature end |
#on_skipped_step(step) ⇒ Object
Adds a step that has been skipped to the output buffer.
148 149 150 |
# File 'lib/spinach/reporter/stdout.rb', line 148 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.
75 76 77 78 79 |
# File 'lib/spinach/reporter/stdout.rb', line 75 def on_successful_step(step, step_location) output_step('✔', step, :green, step_location) self.scenario = [current_feature, current_scenario, step] successful_steps << scenario end |
#on_undefined_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
114 115 116 117 118 |
# File 'lib/spinach/reporter/stdout.rb', line 114 def on_undefined_step(step, failure) output_step('?', step, :yellow) self.scenario_error = [current_feature, current_scenario, step, failure] undefined_steps << scenario_error end |
#output_step(symbol, step, color, step_location = nil) ⇒ Object
Adds to the output buffer a step result
167 168 169 170 171 172 |
# File 'lib/spinach/reporter/stdout.rb', line 167 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 |
#run_summary ⇒ Object
Prints the feature success summary for this run.
188 189 190 191 192 193 194 |
# File 'lib/spinach/reporter/stdout.rb', line 188 def run_summary successful_summary = "(".colorize(:green)+successful_steps.length.to_s.colorize(:light_green)+") Successful".colorize(:green) undefined_summary = "(".colorize(:yellow)+undefined_steps.length.to_s.colorize(:light_yellow)+") Undefined".colorize(:yellow) failed_summary = "(".colorize(:red)+failed_steps.length.to_s.colorize(:light_red)+") Failed".colorize(:red) error_summary = "(".colorize(:red)+error_steps.length.to_s.colorize(:light_red)+") Error".colorize(:red) out.puts "Steps Summary: #{successful_summary}, #{undefined_summary}, #{failed_summary}, #{error_summary}\n\n" end |