Sha256: 0e72346cccf6a271d46bd258b4f5414cc0e5d2f8a45ab72fd9cd44cf36f12d2c

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require_relative "../../ext/test"
require_relative "ext"

module Datadog
  module CI
    module Contrib
      module RSpec
        # Instrument RSpec::Core::ExampleGroup
        module ExampleGroup
          def self.included(base)
            base.singleton_class.prepend(ClassMethods)
          end

          # Instance methods for configuration
          module ClassMethods
            def run(reporter = ::RSpec::Core::NullReporter)
              return super if ::RSpec.configuration.dry_run?
              return super unless datadog_configuration[:enabled]
              return super unless top_level?

              suite_name = "#{description} at #{file_path}"
              test_suite = test_visibility_component.start_test_suite(suite_name)

              success = super
              return success unless test_suite

              if success && test_suite.passed_tests_count > 0
                test_suite.passed!
              elsif success
                test_suite.skipped!
              else
                test_suite.failed!
              end

              test_suite.finish

              success
            end

            private

            def datadog_configuration
              Datadog.configuration.ci[:rspec]
            end

            def test_visibility_component
              Datadog.send(:components).test_visibility
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
datadog-ci-1.3.0 lib/datadog/ci/contrib/rspec/example_group.rb