Sha256: 71741f7c5a8e5a7e30c14464c3598d192eff5e9c96a56a4c006851c3d4567ef3

Contents?: true

Size: 1.05 KB

Versions: 48

Compression:

Stored size: 1.05 KB

Contents

require 'rails_helper'

describe LHC do
  context 'interceptor' do
    before(:each) do
      class CacheInterceptor < LHC::Interceptor

        def before_request(_request)
          LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from cache'), nil)
        end
      end
      LHC.configure { |c| c.interceptors = [CacheInterceptor] }
    end

    it 'can return a response rather then doing a real request' do
      response = LHC.get('http://local.ch')
      expect(response.body).to eq 'Im served from cache'
    end

    context 'misusage' do
      before(:each) do
        class AnotherInterceptor < LHC::Interceptor
          def before_request(_request)
            LHC::Response.new(Typhoeus::Response.new({}), nil)
          end
        end
      end

      it 'raises an exception when two interceptors try to return a response' do
        expect(lambda {
          LHC.get('http://local.ch', interceptors: [CacheInterceptor, AnotherInterceptor])
        }).to raise_error 'Response already set from another interceptor'
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
lhc-7.3.3 spec/interceptors/return_response_spec.rb
lhc-7.3.2 spec/interceptors/return_response_spec.rb
lhc-7.3.1 spec/interceptors/return_response_spec.rb
lhc-7.3.0 spec/interceptors/return_response_spec.rb
lhc-7.2.0 spec/interceptors/return_response_spec.rb
lhc-7.1.0 spec/interceptors/return_response_spec.rb
lhc-7.0.1 spec/interceptors/return_response_spec.rb
lhc-7.0.0 spec/interceptors/return_response_spec.rb
lhc-7.0.0.beta1 spec/interceptors/return_response_spec.rb
lhc-6.7.2 spec/interceptors/return_response_spec.rb
lhc-6.7.1 spec/interceptors/return_response_spec.rb
lhc-6.7.0 spec/interceptors/return_response_spec.rb
lhc-6.6.0.zipkin.pre.03 spec/interceptors/return_response_spec.rb
lhc-6.6.0.zipkin.pre.02 spec/interceptors/return_response_spec.rb
lhc-6.6.0.zipkin.pre.01 spec/interceptors/return_response_spec.rb
lhc-6.6.0.zipkin.pre spec/interceptors/return_response_spec.rb
lhc-6.6.0 spec/interceptors/return_response_spec.rb
lhc-6.5.0 spec/interceptors/return_response_spec.rb
lhc-6.4.0 spec/interceptors/return_response_spec.rb
lhc-6.3.1 spec/interceptors/return_response_spec.rb