Sha256: d8e77985aee29bee470e2eae23cc9f741ed353d1a64685fe9a18e256ca93df8d

Contents?: true

Size: 1 KB

Versions: 13

Compression:

Stored size: 1 KB

Contents

require 'rails_helper'

describe LHC do
  context 'interceptor' do
    before(:each) do
      class Services
        def self.timing(_path, _time); end
      end

      class StatsTimingInterceptor < LHC::Interceptor
        def after_response
          uri = URI.parse(response.request.url)
          path = [
            'web',
            Rails.application.class.parent_name,
            Rails.env,
            response.request.method,
            uri.scheme,
            uri.host,
            response.code
          ].join('.')
          Services.timing(path.downcase, response.time)
        end
      end
      LHC.configure { |c| c.interceptors = [StatsTimingInterceptor] }
    end

    let(:url) { "http://local.ch/v2/feedbacks/-Sc4_pYNpqfsudzhtivfkA" }

    it 'can take action after a response was received' do
      allow(Services).to receive(:timing).with('web.dummy.test.get.http.local.ch.200', 0)
      stub_request(:get, url)
      LHC.get(url)
      expect(Services).to have_received(:timing)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
lhc-10.1.2 spec/interceptors/after_response_spec.rb
lhc-10.1.1 spec/interceptors/after_response_spec.rb
lhc-10.1.0 spec/interceptors/after_response_spec.rb
lhc-10.0.2 spec/interceptors/after_response_spec.rb
lhc-9.4.4 spec/interceptors/after_response_spec.rb
lhc-10.0.1 spec/interceptors/after_response_spec.rb
lhc-10.0.0 spec/interceptors/after_response_spec.rb
lhc-9.4.3 spec/interceptors/after_response_spec.rb
lhc-9.4.2 spec/interceptors/after_response_spec.rb
lhc-9.4.1 spec/interceptors/after_response_spec.rb
lhc-9.4.0 spec/interceptors/after_response_spec.rb
lhc-9.3.1 spec/interceptors/after_response_spec.rb
lhc-9.3.0 spec/interceptors/after_response_spec.rb