Sha256: dc7ad4d69a938f65c315655800873cf9556a8741485b7aa463093796f5e0026a

Contents?: true

Size: 1.88 KB

Versions: 6

Compression:

Stored size: 1.88 KB

Contents

describe Appsignal::Hooks::ExconHook do
  before :context do
    start_agent
  end

  context "with Excon" do
    before(:context) do
      class Excon
        def self.defaults
          @defaults ||= {}
        end
      end
      Appsignal::Hooks::ExconHook.new.install
    end
    after(:context) { Object.send(:remove_const, :Excon) }

    describe "#dependencies_present?" do
      subject { described_class.new.dependencies_present? }

      it { is_expected.to be_truthy }
    end

    describe "#install" do
      it "adds the AppSignal instrumentor to Excon" do
        expect(Excon.defaults[:instrumentor]).to eql(Appsignal::Integrations::ExconIntegration)
      end
    end

    describe "instrumentation" do
      let!(:transaction) do
        Appsignal::Transaction.create("uuid", Appsignal::Transaction::HTTP_REQUEST, "test")
      end
      around { |example| keep_transactions { example.run } }

      it "instruments a http request" do
        data = {
          :host => "www.google.com",
          :method => :get,
          :scheme => "http"
        }
        Excon.defaults[:instrumentor].instrument("excon.request", data) {} # rubocop:disable Lint/EmptyBlock

        expect(transaction).to include_event(
          "name" => "request.excon",
          "title" => "GET http://www.google.com",
          "body" => ""
        )
      end

      it "instruments a http response" do
        data = { :host => "www.google.com" }
        Excon.defaults[:instrumentor].instrument("excon.response", data) {} # rubocop:disable Lint/EmptyBlock

        expect(transaction).to include_event(
          "name" => "response.excon",
          "title" => "www.google.com",
          "body" => ""
        )
      end
    end
  end

  context "without Excon" do
    describe "#dependencies_present?" do
      subject { described_class.new.dependencies_present? }

      it { is_expected.to be_falsy }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
appsignal-3.11.0-java spec/lib/appsignal/hooks/excon_spec.rb
appsignal-3.11.0 spec/lib/appsignal/hooks/excon_spec.rb
appsignal-3.10.0-java spec/lib/appsignal/hooks/excon_spec.rb
appsignal-3.10.0 spec/lib/appsignal/hooks/excon_spec.rb
appsignal-3.9.3-java spec/lib/appsignal/hooks/excon_spec.rb
appsignal-3.9.3 spec/lib/appsignal/hooks/excon_spec.rb