Class: Cucumber::Formatter::Rerun

Inherits:
Object
  • Object
show all
Includes:
Io
Defined in:
lib/cucumber/formatter/rerun.rb

Overview

The formatter used for --format rerun

This formatter keeps track of all failing features and print out their location. Example:

features/foo.feature:34 features/bar.feature:11:76:81

This formatter is used by AutoTest - it will use the output to decide what to run the next time, simply passing the output string on the command line.

Instance Method Summary collapse

Methods included from Io

#ensure_dir, #ensure_file, #ensure_io

Constructor Details

#initialize(runtime, path_or_io, options) ⇒ Rerun

Returns a new instance of Rerun.



18
19
20
21
22
23
# File 'lib/cucumber/formatter/rerun.rb', line 18

def initialize(runtime, path_or_io, options)
  @io = ensure_io(path_or_io, "rerun")
  @options = options
  @file_names = []
  @file_colon_lines = Hash.new{|h,k| h[k] = []}
end

Instance Method Details

#after_examples(*args) ⇒ Object



73
74
75
76
77
78
# File 'lib/cucumber/formatter/rerun.rb', line 73

def after_examples(*args)
  @in_examples = false
  if @current_example_line and @rerun
    @lines << @current_example_line
  end
end

#after_featureObject



30
31
32
33
34
35
36
37
38
# File 'lib/cucumber/formatter/rerun.rb', line 30

def after_feature(*)
  unless @lines.empty?
    after_first_time do
      @io.print ' '
    end
    @io.print "#{@file}:#{@lines.join(':')}"
    @io.flush
  end
end

#after_feature_element(feature_element) ⇒ Object



48
49
50
51
52
53
# File 'lib/cucumber/formatter/rerun.rb', line 48

def after_feature_element(feature_element)
  return if Cucumber::Ast::ScenarioOutline === feature_element
  if  @rerun || feature_element.failed? || feature_element.status == :skipped
    @lines << feature_element.line
  end
end

#after_features(features) ⇒ Object



40
41
42
# File 'lib/cucumber/formatter/rerun.rb', line 40

def after_features(features)
  @io.close
end

#after_table_row(table_row) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cucumber/formatter/rerun.rb', line 55

def after_table_row(table_row)
  return unless @in_examples and Cucumber::Ast::OutlineTable::ExampleRow === table_row
  unless @header_row
    if table_row.failed? || table_row.status == :skipped
      @rerun = true
      @lines << table_row.line
    end
  end

  @header_row = false if @header_row
end

#before_examples(*args) ⇒ Object



67
68
69
70
71
# File 'lib/cucumber/formatter/rerun.rb', line 67

def before_examples(*args)
  @header_row = true
  @in_examples = true
  @current_example_line = nil
end

#before_feature(feature_element) ⇒ Object



25
26
27
28
# File 'lib/cucumber/formatter/rerun.rb', line 25

def before_feature(feature_element)
  @lines = []
  @file = feature_element.file
end

#before_feature_element(feature_element) ⇒ Object



44
45
46
# File 'lib/cucumber/formatter/rerun.rb', line 44

def before_feature_element(feature_element)
  @rerun = false
end

#before_table_row(table_row) ⇒ Object



80
81
82
# File 'lib/cucumber/formatter/rerun.rb', line 80

def before_table_row(table_row)
  return unless @in_examples
end

#scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/cucumber/formatter/rerun.rb', line 88

def scenario_name(keyword, name, file_colon_line, source_indent)
  return unless @in_examples
  if @current_example_line and @rerun
    @lines << @current_example_line
  end
  @rerun = false
  @current_example_line = file_colon_line.split(':')[1]
end

#step_name(keyword, step_match, status, source_indent, background, file_colon_line) ⇒ Object



84
85
86
# File 'lib/cucumber/formatter/rerun.rb', line 84

def step_name(keyword, step_match, status, source_indent, background, file_colon_line)
  @rerun = true if [:failed, :pending, :undefined].index(status)
end