Sha256: c00954f480867bb201a45341f56226766519db54347272859074b9a723187e6c

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require 'cucumber/core/filter'
require 'cucumber/running_test_case'
require 'cucumber/events'

module Cucumber
  module Filters
    class Retry < Core::Filter.new(:configuration)
      def initialize(*_args)
        super
        @total_permanently_failed = 0
      end

      def test_case(test_case)
        configuration.on_event(:test_case_finished) do |event|
          next unless retry_required?(test_case, event)

          test_case_counts[test_case] += 1
          test_case.describe_to(receiver)
        end

        super
      end

      private

      def retry_required?(test_case, event)
        return false unless event.test_case == test_case

        return false unless event.result.failed?

        return false if @total_permanently_failed >= configuration.retry_total_tests

        retry_required = test_case_counts[test_case] < configuration.retry_attempts
        if retry_required
          # retry test
          true
        else
          # test failed after max. attempts
          @total_permanently_failed += 1
          false
        end
      end

      def test_case_counts
        @test_case_counts ||= Hash.new { |h, k| h[k] = 0 }
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
cucumber-9.2.1 lib/cucumber/filters/retry.rb
cucumber-9.2.0 lib/cucumber/filters/retry.rb
cucumber-9.1.2 lib/cucumber/filters/retry.rb
cucumber-9.1.1 lib/cucumber/filters/retry.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.1.0/lib/cucumber/filters/retry.rb
cucumber-9.1.0 lib/cucumber/filters/retry.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/cucumber-9.0.2/lib/cucumber/filters/retry.rb
cucumber-9.0.2 lib/cucumber/filters/retry.rb
cucumber-9.0.1 lib/cucumber/filters/retry.rb
cucumber-9.0.0 lib/cucumber/filters/retry.rb