Sha256: be8b5ba39143077dba44903bcac1d0ee1357709d09dd04dad7068d5340e44e13
Contents?: true
Size: 1.75 KB
Versions: 2
Compression:
Stored size: 1.75 KB
Contents
require 'spec_helper' describe Zeppelin::Middleware::ResponseRaiseError do let(:not_found_response) { [404, { 'X-Reason' => 'because' }, 'keep looking'] } let(:error_response) { [500, { 'X-Error' => 'bailout' }, 'fail' ] } subject do Faraday.new do |b| b.use(described_class) b.adapter :test do |stub| stub.get('ok') { [200, { 'Content-Type' => 'text/html' }, '<body></body>'] } stub.get('not-found') { not_found_response } stub.get('error') { error_response } end end end it 'does nothing when the response is successful' do expect { subject.get('ok') }.to_not raise_error end context 'resource not found' do it 'raises Zeppelin::ResourceNotFound error' do expect { subject.get('not-found') }.to raise_error(Zeppelin::ResourceNotFound) end it "does not destroy the response object stored in the error" do begin subject.get('not-found') rescue Zeppelin::ResourceNotFound => ex expect(ex.response[:status]).to eql(not_found_response[0]) expect(ex.response[:headers]).to eql(not_found_response[1]) expect(ex.response[:body]).to eql(not_found_response[2]) end end end context 'client error' do it 'raises Zeppelin::ClientError error' do expect { subject.get('error') }.to raise_error(Zeppelin::ClientError) end it "does not destroy the response object stored in the error" do begin subject.get('error') rescue Zeppelin::ClientError => ex expect(ex.response[:status]).to eql(error_response[0]) expect(ex.response[:headers]).to eql(error_response[1]) expect(ex.response[:body]).to eql(error_response[2]) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
zeppelin-0.8.4 | spec/middleware/response_raise_error_spec.rb |
zeppelin-0.8.3 | spec/middleware/response_raise_error_spec.rb |