Class: Spinach::Reporter::Progress

Inherits:
Spinach::Reporter show all
Includes:
Reporting
Defined in:
lib/spinach/reporter/progress.rb

Overview

The Progress 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

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, #after_scenario_run, #around_scenario_run, #before_feature_run, #before_run, #before_scenario_run, #bind, #clear_current_feature, #clear_current_scenario, #on_feature_not_found, #set_current_feature, #set_current_scenario

Constructor Details

#initialize(*args) ⇒ Progress

Initializes the reporter

Parameters:

  • options (Hash)

    Sets a custom output buffer by setting options Sets a custom error buffer by setting options



17
18
19
20
21
# File 'lib/spinach/reporter/progress.rb', line 17

def initialize(*args)
  super(*args)
  @out = options[:output] || $stdout
  @error = options[:error] || $stderr
end

Instance Method Details

#on_error_step(step, failure, step_location, step_definitions = nil) ⇒ Object

Adds a step that has raised an error to the output buffer.

Parameters:

  • step (Hash)

    The step in a JSON GherkinRuby format

  • failure (Exception)

    The exception that caused the failure



59
60
61
62
63
# File 'lib/spinach/reporter/progress.rb', line 59

def on_error_step(step, failure, step_location, step_definitions = nil)
  output_step('E', :red)
  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.

Parameters:

  • step (Hash)

    The step in a JSON GherkinRuby format

  • failure (Exception)

    The exception that caused the failure



45
46
47
48
49
# File 'lib/spinach/reporter/progress.rb', line 45

def on_failed_step(step, failure, step_location, step_definitions = nil)
  output_step('F', :red)
  self.scenario_error = [current_feature, current_scenario, step, failure]
  failed_steps << scenario_error
end

#on_pending_step(step, failure) ⇒ Object

Adds an undefined step to the output buffer.

Parameters:

  • step (Hash)

    The step in a JSON GherkinRuby format



81
82
83
84
85
# File 'lib/spinach/reporter/progress.rb', line 81

def on_pending_step(step, failure)
  output_step('P', :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.

Parameters:

  • step (Hash)

    The step that GherkinRuby extracts



92
93
94
# File 'lib/spinach/reporter/progress.rb', line 92

def on_skipped_step(step, step_definitions = nil)
  output_step('~', :cyan)
end

#on_successful_step(step, step_location, step_definitions = nil) ⇒ Object

Adds a passed step to the output buffer.

Parameters:

  • step (Step)

    The step.

  • step_location (Array)

    The step source location



31
32
33
34
35
# File 'lib/spinach/reporter/progress.rb', line 31

def on_successful_step(step, step_location, step_definitions = nil)
  output_step('.', :green)
  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.

Parameters:

  • step (Hash)

    The step in a JSON GherkinRuby format



70
71
72
73
74
# File 'lib/spinach/reporter/progress.rb', line 70

def on_undefined_step(step, failure, step_definitions = nil)
  output_step('U', :yellow)
  self.scenario_error = [current_feature, current_scenario, step, failure]
  undefined_steps << scenario_error
end

#output_step(text, color = :grey) ⇒ Object

Adds to the output buffer a step result

Parameters:

  • text (String)

    A symbol to prepend before the step keyword (might be useful to indicate if everything went ok or not).

  • color (Symbol) (defaults to: :grey)

    The color code to use with Colorize to colorize the output.



105
106
107
# File 'lib/spinach/reporter/progress.rb', line 105

def output_step(text, color = :grey)
  out.print(text.to_s.colorize(color))
end