Sha256: 391ffc8367ab8eda3b9028f4a3f8248cac3777f1ba8fc47118ba1817d203ffd1

Contents?: true

Size: 1.14 KB

Versions: 14

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

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

        def before_request
          LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok, 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
            LHC::Response.new(Typhoeus::Response.new(response_code: 200, return_code: :ok), 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

14 entries across 14 versions & 1 rubygems

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