Sha256: 039a036b01b5e955941d29a36c05720fe12a53fe2896c375b8f3733976f6556d

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 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 && knapsack_version >= Gem::Version.new("7")
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datadog-ci-1.0.1 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.0.0 lib/datadog/ci/contrib/rspec/patcher.rb
datadog-ci-1.0.0.beta6 lib/datadog/ci/contrib/rspec/patcher.rb