summaryrefslogtreecommitdiff
path: root/qa/qa/support/formatters/quarantine_formatter.rb
blob: c5d16988dbdd65457b355fe05fcf1630fbe4da25 (plain)
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
37
38
39
40
41
42
# frozen_string_literal: true

module QA
  module Support
    module Formatters
      class QuarantineFormatter < ::RSpec::Core::Formatters::BaseFormatter
        include Specs::Helpers::Quarantine

        ::RSpec::Core::Formatters.register(
          self,
          :example_group_started,
          :example_started
        )

        # Starts example group
        # @param [RSpec::Core::Notifications::GroupNotification] example_group_notification
        # @return [void]
        def example_group_started(example_group_notification)
          group = example_group_notification.group

          skip_or_run_quarantined_tests_or_contexts(filters, group)
        end

        # Starts example
        # @param [RSpec::Core::Notifications::ExampleNotification] example_notification
        # @return [void]
        def example_started(example_notification)
          example = example_notification.example

          # if skip propagated from example_group, do not reset skip metadata
          skip_or_run_quarantined_tests_or_contexts(filters, example) unless example.metadata[:skip]
        end

        private

        def filters
          @filters ||= ::RSpec.configuration.inclusion_filter.rules
        end
      end
    end
  end
end