Class: Cucumber::Formatter::Rerun

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

Instance Method Summary collapse

Methods included from Io

ensure_dir, ensure_file, ensure_io

Constructor Details

#initialize(config) ⇒ Rerun

rubocop:disable Metrics/PerceivedComplexity


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cucumber/formatter/rerun.rb', line 10

def initialize(config) # rubocop:disable Metrics/PerceivedComplexity
  @io = ensure_io(config.out_stream)
  @config = config
  @failures = {}
  config.on_event :test_case_finished do |event|
    test_case, result = *event.attributes
    if @config.strict.strict?(:flaky)
      next if result.ok?(@config.strict)
      add_to_failures(test_case)
    else
      unless @latest_failed_test_case.nil?
        if @latest_failed_test_case != test_case
          add_to_failures(@latest_failed_test_case)
          @latest_failed_test_case = nil
        elsif result.ok?(@config.strict)
          @latest_failed_test_case = nil
        end
      end
      @latest_failed_test_case = test_case unless result.ok?(@config.strict)
    end
  end
  config.on_event :test_run_finished do
    add_to_failures(@latest_failed_test_case) unless @latest_failed_test_case.nil?
    next if @failures.empty?
    @io.print file_failures.join("\n")
  end
end