Class: Spinach::Reporter::Console
- Inherits:
-
Spinach::Reporter
- Object
- Spinach::Reporter
- Spinach::Reporter::Console
- Includes:
- ErrorReporting
- Defined in:
- lib/spinach-console-reporter/console.rb
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.
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) ⇒ Console
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
Constructor Details
#initialize(*args) ⇒ Console
Initialitzes the runner
22 23 24 25 26 27 |
# File 'lib/spinach-console-reporter/console.rb', line 22 def initialize(*args) super(*args) @out = [:output] || $stdout @error = [:error] || $stdout @max_step_name_length = 0 end |
Instance Attribute Details
#error ⇒ Object (readonly)
The output buffers to store the reports.
8 9 10 |
# File 'lib/spinach-console-reporter/console.rb', line 8 def error @error end |
#out ⇒ Object (readonly)
The output buffers to store the reports.
8 9 10 |
# File 'lib/spinach-console-reporter/console.rb', line 8 def out @out end |
#scenario ⇒ Object
The last scenario
14 15 16 |
# File 'lib/spinach-console-reporter/console.rb', line 14 def scenario @scenario end |
#scenario_error ⇒ Object
The last scenario error
11 12 13 |
# File 'lib/spinach-console-reporter/console.rb', line 11 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
196 197 198 199 200 |
# File 'lib/spinach-console-reporter/console.rb', line 196 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
55 56 57 58 59 60 |
# File 'lib/spinach-console-reporter/console.rb', line 55 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
34 35 36 37 |
# File 'lib/spinach-console-reporter/console.rb', line 34 def before_feature_run(feature) name = feature.name out.puts %Q|\n#{magenta("Feature:")} #{magenta(name)}| end |
#before_scenario_run(scenario, step_definitions = nil) ⇒ Object
Prints the scenario name to the standard ouput
44 45 46 47 48 |
# File 'lib/spinach-console-reporter/console.rb', line 44 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 #{green('Scenario:')} #{green(name)}" end |
#full_step(step) ⇒ Object
Constructs the full step definition
219 220 221 |
# File 'lib/spinach-console-reporter/console.rb', line 219 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.
98 99 100 101 102 |
# File 'lib/spinach-console-reporter/console.rb', line 98 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.
84 85 86 87 88 |
# File 'lib/spinach-console-reporter/console.rb', line 84 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.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/spinach-console-reporter/console.rb', line 134 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.
120 121 122 123 124 |
# File 'lib/spinach-console-reporter/console.rb', line 120 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.
154 155 156 |
# File 'lib/spinach-console-reporter/console.rb', line 154 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.
70 71 72 73 74 |
# File 'lib/spinach-console-reporter/console.rb', line 70 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.
109 110 111 112 113 |
# File 'lib/spinach-console-reporter/console.rb', line 109 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
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/spinach-console-reporter/console.rb', line 173 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 + 30 # Colorize and output format correction # REMEMBER TO CORRECT PREVIOUS MAX LENGTH IF OUTPUT FORMAT IS MODIFIED buffer = [] buffer << indent(4) # buffer << symbol.foreground(color).bright buffer << indent(2) buffer << send(color, step.keyword) buffer << indent(1) buffer << send(color, step.name) joined = buffer.join.ljust(max_length) out.puts(joined + white(step_location.to_s)) end |
#run_summary ⇒ Object
Prints the feature success summary for this run.
204 205 206 207 208 209 210 211 212 |
# File 'lib/spinach-console-reporter/console.rb', line 204 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 |