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, #pending_steps, #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(scenario, step_definitions = nil) ⇒ Object
Adds an error report and re.
-
#before_feature_run(feature) ⇒ Object
Prints the feature name to the standard output.
-
#before_scenario_run(scenario, step_definitions = nil) ⇒ 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, step_definitions = nil) ⇒ Object
Adds a step that has raised an error to the output buffer.
-
#on_failed_step(step, failure, step_location, step_definitions = nil) ⇒ 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_pending_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
-
#on_skipped_step(step, step_definitions = nil) ⇒ Object
Adds a step that has been skipped to the output buffer.
-
#on_successful_step(step, step_location, step_definitions = nil) ⇒ Object
Adds a passed step to the output buffer.
-
#on_undefined_step(step, failure, step_definitions = nil) ⇒ 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_pending_steps, #report_undefined_features, #report_undefined_steps, #summarized_error
Methods inherited from Spinach::Reporter
#after_feature_run, #around_scenario_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
201 202 203 204 205 |
# File 'lib/spinach/reporter/stdout.rb', line 201 def after_run(success) error_summary unless success out.puts "" run_summary end |
#after_scenario_run(scenario, step_definitions = nil) ⇒ 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(scenario, step_definitions = nil) if scenario_error report_error(scenario_error, :full) self.scenario_error = nil end end |
#before_feature_run(feature) ⇒ 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(feature) name = feature.name out.puts "\n#{'Feature:'.magenta} #{name.light_magenta}" end |
#before_scenario_run(scenario, step_definitions = nil) ⇒ 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(scenario, step_definitions = nil) @max_step_name_length = scenario.steps.map(&:name).map(&:length).max if scenario.steps.any? name = scenario.name out.puts "\n #{'Scenario:'.green} #{name.light_green}" end |
#full_step(step) ⇒ Object
Constructs the full step definition
224 225 226 |
# File 'lib/spinach/reporter/stdout.rb', line 224 def full_step(step) "#{step.keyword} #{step.name}" end |
#on_error_step(step, failure, step_location, step_definitions = nil) ⇒ 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, step_definitions = nil) 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, step_definitions = nil) ⇒ 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, step_definitions = nil) 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.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/spinach/reporter/stdout.rb', line 139 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_pending_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
125 126 127 128 129 |
# File 'lib/spinach/reporter/stdout.rb', line 125 def on_pending_step(step, failure) output_step('P', step, :yellow) self.scenario_error = [current_feature, current_scenario, step, failure] pending_steps << scenario_error end |
#on_skipped_step(step, step_definitions = nil) ⇒ Object
Adds a step that has been skipped to the output buffer.
159 160 161 |
# File 'lib/spinach/reporter/stdout.rb', line 159 def on_skipped_step(step, step_definitions = nil) output_step('~', step, :cyan) end |
#on_successful_step(step, step_location, step_definitions = nil) ⇒ 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, step_definitions = nil) output_step('✔', step, :green, step_location) self.scenario = [current_feature, current_scenario, step] successful_steps << scenario end |
#on_undefined_step(step, failure, step_definitions = nil) ⇒ 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, step_definitions = nil) 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
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/spinach/reporter/stdout.rb', line 178 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 buffer = [] buffer << indent(4) buffer << symbol.colorize(:"light_#{color}") buffer << indent(2) buffer << step.keyword.colorize(:"light_#{color}") buffer << indent(1) buffer << step.name.colorize(color) joined = buffer.join.ljust(max_length) out.puts(joined + step_location.to_s.colorize(:grey)) end |
#run_summary ⇒ Object
Prints the feature success summary for this run.
209 210 211 212 213 214 215 216 217 |
# File 'lib/spinach/reporter/stdout.rb', line 209 def run_summary successful_summary = format_summary(:green, successful_steps, 'Successful') undefined_summary = format_summary(:yellow, undefined_steps, 'Undefined') pending_summary = format_summary(:yellow, pending_steps, 'Pending') failed_summary = format_summary(:red, failed_steps, 'Failed') error_summary = format_summary(:red, error_steps, 'Error') out.puts "Steps Summary: #{successful_summary}, #{undefined_summary}, #{pending_summary}, #{failed_summary}, #{error_summary}\n\n" end |