Sha256: 65e4302495d5594664e38e60f47f3e9a0b62c35b7de5a556d0a2614ca51424cf

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

require 'rails_helper'

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

    before(:each) do
      class StatsTimingInterceptor < LHC::Interceptor
        def after_response(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
      described_class.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)
      described_class.get(url)
      expect(Services).to have_received(:timing)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lhc-3.5.4 spec/interceptors/after_response_spec.rb
lhc-3.5.3 spec/interceptors/after_response_spec.rb
lhc-3.5.2 spec/interceptors/after_response_spec.rb
lhc-3.5.1 spec/interceptors/after_response_spec.rb
lhc-3.5.0 spec/interceptors/after_response_spec.rb