Class: Specjour::Cucumber::DistributedFormatter

Inherits:
Cucumber::Formatter::Progress
  • Object
show all
Defined in:
lib/specjour/cucumber/distributed_formatter.rb

Constant Summary

OUTCOMES =
[:failed, :skipped, :undefined, :pending, :passed]

Instance Method Summary (collapse)

Constructor Details

- (DistributedFormatter) initialize(step_mother, io, options)

Returns a new instance of DistributedFormatter



5
6
7
8
9
10
11
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 5

def initialize(step_mother, io, options)
  @step_mother = step_mother
  @io = io
  @options = options
  @failing_scenarios = []
  @step_summary = []
end

Instance Method Details

- (Object) after_features(features)



13
14
15
16
17
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 13

def after_features(features)
  print_summary
  step_mother.scenarios.clear
  step_mother.steps.clear
end

- (Object) prepare_elements(elements, status, kind)



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 34

def prepare_elements(elements, status, kind)
  output = ''
  if elements.any?
    output += format_string("\n(::) #{status} #{kind} (::)\n", status)
    output += "\n"
  end

  elements.each_with_index do |element, i|
    if status == :failed
      output += print_exception(element.exception, status, 0)
    else
      output += format_string(element.backtrace_line, status)
      output += "\n"
    end
    @step_summary << output unless output.nil? || output.empty?
  end
end

- (Object) prepare_failures



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 19

def prepare_failures
  step_mother.scenarios(:failed).select do |s|
    s.is_a?(Cucumber::Ast::Scenario) || s.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)
  end.map do |failure|
    if failure.is_a?(Cucumber::Ast::Scenario)
      failure
    elsif failure.is_a?(Cucumber::Ast::OutlineTable::ExampleRow)
      failure.scenario_outline
    end
  end.each do |failure|
    @failing_scenarios << format_string("cucumber " + failure.file_colon_line[2..-1], :failed) +
                          format_string(" # Scenario: " + failure.name, :comment)
  end
end

- (Object) prepare_steps(type)



52
53
54
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 52

def prepare_steps(type)
  prepare_elements(step_mother.steps(type), type, 'steps')
end


56
57
58
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 56

def print_exception(e, status, indent)
  format_string("#{e.message} (#{e.class})\n#{e.backtrace.join("\n")}".indent(indent), status)
end


60
61
62
63
64
65
66
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 60

def print_summary
  prepare_failures
  prepare_steps(:failed)
  prepare_steps(:undefined)

  @io.send_message(:cucumber_summary=, to_hash)
end

- (Object) to_hash



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/specjour/cucumber/distributed_formatter.rb', line 70

def to_hash
  hash = {}
  [:scenarios, :steps].each do |type|
    hash[type] = {}
    OUTCOMES.each do |outcome|
      hash[type][outcome] = step_mother.send(type, outcome).size
    end
  end
  hash.merge!(:failing_scenarios => @failing_scenarios, :step_summary => @step_summary)
  hash
end