Sha256: f83bbf44ccbeec7a36788a28ba0a78cd02cada72d7f7952863ea3b58db0fa505

Contents?: true

Size: 1.15 KB

Versions: 14

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

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',
            ((ActiveSupport.gem_version >= Gem::Version.new('6.0.0')) ? Rails.application.class.module_parent_name : Rails.application.class.parent_name).underscore,
            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

14 entries across 14 versions & 1 rubygems

Version Path
lhc-15.2.1 spec/interceptors/after_response_spec.rb
lhc-15.2.0 spec/interceptors/after_response_spec.rb
lhc-15.1.3 spec/interceptors/after_response_spec.rb
lhc-15.1.2 spec/interceptors/after_response_spec.rb
lhc-15.1.1 spec/interceptors/after_response_spec.rb
lhc-15.1.0 spec/interceptors/after_response_spec.rb
lhc-16.0.0.pre.pro2162.2 spec/interceptors/after_response_spec.rb
lhc-16.0.0.pre.pro2162 spec/interceptors/after_response_spec.rb
lhc-15.0.1 spec/interceptors/after_response_spec.rb
lhc-15.0.0 spec/interceptors/after_response_spec.rb
lhc-14.0.0 spec/interceptors/after_response_spec.rb
lhc-13.4.0.pre.pro1766.1 spec/interceptors/after_response_spec.rb
lhc-13.2.0 spec/interceptors/after_response_spec.rb
lhc-13.1.0 spec/interceptors/after_response_spec.rb