File: failures_logger.rb

package info (click to toggle)
ruby-parallel-tests 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 760 kB
  • sloc: ruby: 5,446; javascript: 16; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 956 bytes parent folder | download
1
2
3
4
5
6
7
8
9
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
# frozen_string_literal: true
require 'cucumber/formatter/rerun'
require 'parallel_tests/gherkin/io'
require 'cucumber/events'

module ParallelTests
  module Cucumber
    class FailuresLogger < ::Cucumber::Formatter::Rerun
      include ParallelTests::Gherkin::Io

      def initialize(config)
        super

        @io = prepare_io(config.out_stream)

        # Remove handler inherited from Cucumber::Formatter::Rerun that does not
        # properly join file failures
        handlers = config.event_bus.instance_variable_get(:@handlers)
        handlers[::Cucumber::Events::TestRunFinished.to_s].pop

        # Add our own handler
        config.on_event :test_run_finished do
          next if @failures.empty?

          lock_output do
            @failures.each do |file, lines|
              lines.each do |line|
                @io.print "#{file}:#{line} "
              end
            end
          end
        end
      end
    end
  end
end