Class: Spinach::Reporter::Stdout
- Inherits:
-
Spinach::Reporter
- Object
- Spinach::Reporter
- Spinach::Reporter::Stdout
- Includes:
- Reporting
- Defined in:
- lib/spinach/reporter/stdout.rb
Overview
The Stdout reporter outputs the runner results to the standard output
Instance Attribute Summary
Attributes included from Reporting
#error, #out, #scenario, #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_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.
-
#initialize(*args) ⇒ Stdout
constructor
Initializes the reporter.
-
#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.
Methods included from Reporting
#after_run, #before_run, #error_summary, #format_summary, #full_error, #full_step, #report_error, #report_error_steps, #report_errors, #report_exception, #report_failed_steps, #report_pending_steps, #report_undefined_features, #report_undefined_steps, #run_summary, #summarized_error
Methods inherited from Spinach::Reporter
#after_feature_run, #after_run, #around_scenario_run, #before_run, #bind, #clear_current_feature, #clear_current_scenario, #set_current_feature, #set_current_scenario
Constructor Details
#initialize(*args) ⇒ Stdout
Initializes the reporter
17 18 19 20 21 22 |
# File 'lib/spinach/reporter/stdout.rb', line 17 def initialize(*args) super(*args) @out = [:output] || $stdout @error = [:error] || $stderr @max_step_name_length = 0 end |
Instance Method Details
#after_scenario_run(scenario, step_definitions = nil) ⇒ Object
Adds an error report and re
50 51 52 53 54 55 |
# File 'lib/spinach/reporter/stdout.rb', line 50 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
29 30 31 32 |
# File 'lib/spinach/reporter/stdout.rb', line 29 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
39 40 41 42 43 |
# File 'lib/spinach/reporter/stdout.rb', line 39 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 |
#on_error_step(step, failure, step_location, step_definitions = nil) ⇒ Object
Adds a step that has raised an error to the output buffer.
93 94 95 96 97 |
# File 'lib/spinach/reporter/stdout.rb', line 93 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.
79 80 81 82 83 |
# File 'lib/spinach/reporter/stdout.rb', line 79 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.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/spinach/reporter/stdout.rb', line 129 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}".red end out.puts "\n\n" undefined_features << feature end |
#on_pending_step(step, failure) ⇒ Object
Adds an undefined step to the output buffer.
115 116 117 118 119 |
# File 'lib/spinach/reporter/stdout.rb', line 115 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.
149 150 151 |
# File 'lib/spinach/reporter/stdout.rb', line 149 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.
65 66 67 68 69 |
# File 'lib/spinach/reporter/stdout.rb', line 65 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.
104 105 106 107 108 |
# File 'lib/spinach/reporter/stdout.rb', line 104 def on_undefined_step(step, failure, step_definitions = nil) output_step('?', step, :red) 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
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/spinach/reporter/stdout.rb', line 168 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 |