Sha256: 50351c08b55711c25287d43f988e7987b7d06b1324c7c2403f6944b92f76e235

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

require "datadog/tracing/contrib/patcher"

require_relative "example"
require_relative "example_group"
require_relative "runner"

module Datadog
  module CI
    module Contrib
      module RSpec
        # Patcher enables patching of 'rspec' module.
        module Patcher
          include Datadog::Tracing::Contrib::Patcher

          module_function

          def target_version
            Integration.version
          end

          def patch
            # ci-queue test runner instrumentation
            # https://github.com/Shopify/ci-queue
            if ci_queue?
              ::RSpec::Queue::Runner.include(Runner)
            end

            if knapsack_pro?
              # Knapsack Pro test runner instrumentation
              # https://github.com/KnapsackPro/knapsack_pro-ruby
              require_relative "knapsack_pro/patcher"
              Datadog::CI::Contrib::RSpec::KnapsackPro::Patcher.patch
            end

            # default rspec test runner instrumentation
            ::RSpec::Core::Runner.include(Runner)

            ::RSpec::Core::Example.include(Example)
            ::RSpec::Core::ExampleGroup.include(ExampleGroup)
          end

          def ci_queue?
            !!defined?(::RSpec::Queue::Runner)
          end

          def knapsack_pro?
            knapsack_version = Gem.loaded_specs["knapsack_pro"]&.version

            # additional instrumentation is needed for KnapsackPro version 7 and later
            !!defined?(::KnapsackPro) &&
              !knapsack_version.nil? && knapsack_version >= Gem::Version.new("7")
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
datadog-ci-1.8.1 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.8.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.7.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.6.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.5.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.4.1 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.4.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.3.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.2.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.1.0 lib/datadog/ci/contrib/rspec/patcher.rb