Sha256: 07f325b338c5480e68bbf481cc8f86faede3c9060a5938b7c270c47d752bf36f
Contents?: true
Size: 1.22 KB
Versions: 35
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true 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 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 if request.response.nil? return LHC::Response.new(Typhoeus::Response.new(response_body: 'Im served from remote cache'), nil) end end end LHC.configure { |c| c.interceptors = [LocalCacheInterceptor, RemoteCacheInterceptor] } end it 'can handle multiple interceptors that compete for returning the response' do response = LHC.get('http://local.ch') expect(response.body).to eq 'Im served from remote cache' LocalCacheInterceptor.cached = true response = LHC.get('http://local.ch') expect(response.body).to eq 'Im served from local cache' end end end
Version data entries
35 entries across 35 versions & 1 rubygems