Module: Spinach::Reporter::Stdout::ErrorReporting

Included in:
Spinach::Reporter::Stdout
Defined in:
lib/spinach/reporter/stdout/error_reporting.rb

Overview

This module handles Stdoutā€™s reporter error reporting capabilities.

Instance Method Summary collapse

Instance Method Details

#error_summaryObject

Prints the errors for this run.



9
10
11
12
13
14
15
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 9

def error_summary
  error.puts "\nError summary:\n"
  report_error_steps
  report_failed_steps
  report_undefined_features
  report_undefined_steps
end

#full_error(error) ⇒ String

Returns a complete error report

Parameters:

  • error (Array)

    An array containing the feature, scenario, step and exception

Returns:

  • (String)

    The coplete error report



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 112

def full_error(error)
  feature, scenario, step, exception = error
  output = "\n"
  output += report_exception(exception)
  output +="\n"

  if exception.kind_of?(Spinach::StepNotDefinedException)
    output << "\n"
    output << "        You can define it with: \n\n".yellow
    suggestion = Generators::StepGenerator.new(step).generate
    suggestion.split("\n").each do |line|
      output << "          #{line}\n".yellow
    end
    output << "\n"
  else
    if options[:backtrace]
      output += "\n"
      exception.backtrace.map do |line|
        output << "        #{line}\n"
      end
    else
      output << "        #{exception.backtrace[0]}"
    end
  end
  output
end

#report_error(error, format = :summarized) ⇒ String

Prints an error in a nice format

Parameters:

  • error (Array)

    An array containing the feature, scenario, step and exception

  • format (Symbol) (defaults to: :summarized)

    The format to output the error. Currently supproted formats are :summarized (default) and :full

Returns:

  • (String)

    The error report



75
76
77
78
79
80
81
82
83
84
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 75

def report_error(error, format=:summarized)
  case format
    when :summarized
      self.error.puts summarized_error(error)
    when :full
      self.error.puts full_error(error)
    else
      raise "Format not defined"
  end
end

#report_error_stepsObject

Prints the steps that raised an error.



19
20
21
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 19

def report_error_steps
  report_errors('Errors', error_steps, :light_red) if error_steps.any?
end

#report_errors(banner, steps, color) ⇒ Object

Prints the error for a given set of steps

Parameters:

  • banner (String)

    the text to prepend as the title

  • steps (Array)

    the steps to output

  • color (Symbol)

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



55
56
57
58
59
60
61
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 55

def report_errors(banner, steps, color)
  error.puts "  #{banner} (#{steps.length})".colorize(color)
  steps.each do |error|
    report_error error
  end
  error.puts ""
end

#report_exception(exception) ⇒ String

Prints a information when an exception is raised.

Parameters:

  • exception (Exception)

    The exception to report

Returns:

  • (String)

    The exception report



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 148

def report_exception(exception)
  output = exception.message.split("\n").map{ |line|
    "        #{line}"
  }.join("\n")

  if exception.kind_of?(Spinach::StepNotDefinedException)
    output.yellow
  else
    output.red
  end
end

#report_failed_stepsObject

Prints failing steps.



25
26
27
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 25

def report_failed_steps
  report_errors('Failures', failed_steps, :light_red) if failed_steps.any?
end

#report_undefined_featuresObject



35
36
37
38
39
40
41
42
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 35

def report_undefined_features
  if undefined_features.any?
    error.puts "  Undefined features (#{undefined_features.length})".light_yellow
    undefined_features.each do |feature|
      error.puts "    #{feature['name']}".yellow
    end
  end
end

#report_undefined_stepsObject

Prints undefined steps.



31
32
33
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 31

def report_undefined_steps
  report_errors('Undefined steps', undefined_steps, :yellow) if undefined_steps.any?
end

#summarized_error(error) ⇒ String

Returns summarized error report

Parameters:

  • error (Array)

    An array containing the feature, scenario, step and exception

Returns:

  • (String)

    The summarized error report



94
95
96
97
98
99
100
101
102
# File 'lib/spinach/reporter/stdout/error_reporting.rb', line 94

def summarized_error(error)
  feature, scenario, step, exception = error
  summary = "    #{feature['name']} :: #{scenario['name']} :: #{full_step step}"
  if exception.kind_of?(Spinach::StepNotDefinedException)
    summary.yellow
  else
    summary.red
  end
end