Sha256: fa25a3d997039884c5111ee35fc333dc5743a9fec59cbd9b2421400714d1e067
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
require 'rails_helper' describe LHC do context 'interceptor response competition' do before(:each) do # rubocop:disable Style/ClassVars class LocalCacheInterceptor < LHC::Interceptor @@cached = false cattr_accessor :cached def before_request(_request) if @@cached return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from local cache'), nil) end end end # rubocop:enable Style/ClassVars class RemoteCacheInterceptor < LHC::Interceptor def before_request(request) if request.response.nil? return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from remote cache'), nil) end end end described_class.configure { |c| c.interceptors = [LocalCacheInterceptor, RemoteCacheInterceptor] } end it 'can handle multiple interceptors that compete for returning the response' do response = described_class.get('http://local.ch') expect(response.body).to eq 'Im served from remote cache' LocalCacheInterceptor.cached = true response = described_class.get('http://local.ch') expect(response.body).to eq 'Im served from local cache' end end end
Version data entries
5 entries across 5 versions & 1 rubygems