Sha256: 716f9d3f3d697e9feebafdd0faab96a97f6bdae8cc3d8d9a54ae7fb15684f1b7

Contents?: true

Size: 1.06 KB

Versions: 10

Compression:

Stored size: 1.06 KB

Contents

require 'rails_helper'

describe LHC do

  context 'interceptor' do

    before(:each) do
      class CacheInterceptor < LHC::Interceptor

        def before_request(request)
          return 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)
            return LHC::Response.new(Typhoeus::Response.new({}), nil)
          end
        end
      end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
lhc-3.4.0 spec/interceptors/return_response_spec.rb
lhc-3.3.0 spec/interceptors/return_response_spec.rb
lhc-3.2.0 spec/interceptors/return_response_spec.rb
lhc-3.1.1 spec/interceptors/return_response_spec.rb
lhc-3.1.0 spec/interceptors/return_response_spec.rb
lhc-3.0.0 spec/interceptors/return_response_spec.rb
lhc-2.0.0 spec/interceptors/return_response_spec.rb
lhc-1.2.0 spec/interceptors/return_response_spec.rb
lhc-1.1.0 spec/interceptors/return_response_spec.rb
lhc-0.2.1 spec/interceptors/return_response_spec.rb