Sha256: d67d9637e718c96256b22cf944223235ee5fbea22609ef67ffb117338888d7e0

Contents?: true

Size: 2 KB

Versions: 10

Compression:

Stored size: 2 KB

Contents

require_relative '../../test'

require_relative '../../ext/app_types'
require_relative '../../ext/environment'
require_relative '../../ext/test'
require_relative 'ext'

module Datadog
  module CI
    module Contrib
      module RSpec
        # Instrument RSpec::Core::Example
        module Example
          def self.included(base)
            base.prepend(InstanceMethods)
          end

          # Instance methods for configuration
          module InstanceMethods
            def run(example_group_instance, reporter)
              return super unless configuration[:enabled]

              test_name = full_description.strip
              if metadata[:description].empty?
                # for unnamed it blocks this appends something like "example at ./spec/some_spec.rb:10"
                test_name += " #{description}"
              end

              CI::Test.trace(
                configuration[:operation_name],
                {
                  span_options: {
                    resource: test_name,
                    service: configuration[:service_name]
                  },
                  framework: Ext::FRAMEWORK,
                  framework_version: CI::Contrib::RSpec::Integration.version.to_s,
                  test_name: test_name,
                  test_suite: metadata[:example_group][:file_path],
                  test_type: Ext::TEST_TYPE
                }
              ) do |span|
                result = super

                case execution_result.status
                when :passed
                  CI::Test.passed!(span)
                when :failed
                  CI::Test.failed!(span, execution_result.exception)
                else
                  CI::Test.skipped!(span, execution_result.exception) if execution_result.example_skipped?
                end

                result
              end
            end

            private

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ddtrace-1.14.0 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.13.1 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.13.0 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.12.1 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.12.0 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.11.1 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.11.0 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.11.0.beta1 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.10.1 lib/datadog/ci/contrib/rspec/example.rb
ddtrace-1.10.0 lib/datadog/ci/contrib/rspec/example.rb