spec/lib/geoblacklight/wms_layer_spec.rb in geoblacklight-1.8.0 vs spec/lib/geoblacklight/wms_layer_spec.rb in geoblacklight-1.9.0

- old
+ new

@@ -54,15 +54,46 @@ end end end describe '#request_response' do + subject(:wms_layer) { described_class.new(params) } let(:params) { rails_4_params } + let(:connection) { instance_double(Faraday::Connection) } + let(:response) { instance_double(Faraday::Response) } + before do + allow(Faraday).to receive(:new).and_return(connection) + end + it 'returns a Faraday object' do - faraday = double('faraday') - allow(faraday).to receive(:get) - expect(Faraday).to receive(:new).and_return(faraday) - described_class.new(params) + allow(connection).to receive(:get).and_return(response) + expect(wms_layer.request_response).to eq(response) + end + + context 'when the HTTP connection fails' do + before do + allow(Geoblacklight.logger).to receive(:error).with('#<Faraday::ConnectionFailed wrapped=#<StandardError: test connection error>>') + allow(connection).to receive(:get).and_raise(Faraday::Error::ConnectionFailed.new(StandardError.new('test connection error'))) + end + + it 'logs the Faraday error' do + expect(Geoblacklight.logger).to receive(:error).exactly(3).times + expect(wms_layer.request_response).to be_a Hash + expect(wms_layer.request_response).to include(error: '#<Faraday::ConnectionFailed wrapped=#<StandardError: test connection error>>') + end + end + + context 'when the HTTP connection times out' do + before do + allow(Geoblacklight.logger).to receive(:error).with('#<Faraday::TimeoutError #<Faraday::TimeoutError: timeout>>') + allow(connection).to receive(:get).and_raise(Faraday::Error::TimeoutError) + end + + it 'logs the Faraday error' do + expect(Geoblacklight.logger).to receive(:error).exactly(3).times + expect(wms_layer.request_response).to be_a Hash + expect(wms_layer.request_response).to include(error: '#<Faraday::TimeoutError #<Faraday::TimeoutError: timeout>>') + end end end end