Sha256: 4ef5f6b722e142dbf164d2a6f5d1f9cf0901fc8b1f59ad5d7e28440a7f1ee3bf

Contents?: true

Size: 1.89 KB

Versions: 17

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

module RSpec::Buildkite::Analytics
  class Network
    module NetHTTPPatch
      def request(request, *args, &block)
        unless uri = request.uri
          protocol = use_ssl? ? "https" : "http"
          uri = URI.join("#{protocol}://#{address}:#{port}", request.path)
        end

        detail = { method: request.method.upcase, url: uri.to_s, lib: "net-http" }

        http_tracer = RSpec::Buildkite::Analytics::Uploader.tracer
        http_tracer&.enter("http", **detail)

        super
      ensure
        http_tracer&.leave
      end
    end

    module VCRPatch
      def handle
        if request_type == :stubbed_by_vcr && tracer = RSpec::Buildkite::Analytics::Uploader.tracer
          tracer.current_span.detail.merge!(stubbed: "vcr")
        end

        super
      end
    end

    module HTTPPatch
      def perform(request, options)
        detail = { method: request.verb.to_s.upcase, url: request.uri.to_s, lib: "http" }

        http_tracer = RSpec::Buildkite::Analytics::Uploader.tracer
        http_tracer&.enter("http", **detail)

        super
      ensure
        http_tracer&.leave
      end
    end

    module WebMockPatch
      def response_for_request(request_signature)
        response_from_webmock = super

        if response_from_webmock && tracer = RSpec::Buildkite::Analytics::Uploader.tracer
          tracer.current_span.detail.merge!(stubbed: "webmock")
        end

        response_from_webmock
      end
    end

    def self.configure
      if defined?(VCR)
        require "vcr/request_handler"
        VCR::RequestHandler.prepend(VCRPatch)
      end

      if defined?(WebMock)
        WebMock::StubRegistry.prepend(WebMockPatch)
      end

      if defined?(Net) && defined?(Net::HTTP)
        Net::HTTP.prepend(NetHTTPPatch)
      end

      if defined?(HTTP) && defined?(HTTP::Client)
        HTTP::Client.prepend(HTTPPatch)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
rspec-buildkite-analytics-0.8.2 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.8.1 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.8.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.7.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.6.3 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.6.1 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.6.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.5.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.4.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.6 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.5 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.4 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.3 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.2 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.1 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.3.0 lib/rspec/buildkite/analytics/network.rb
rspec-buildkite-analytics-0.2.0 lib/rspec/buildkite/analytics/network.rb