add tests for array response behaviour

This commit is contained in:
sirnicolaz 2015-11-18 11:56:52 +01:00
parent c0327a4b8d
commit a4daa56c53
2 changed files with 19 additions and 1 deletions

View File

@ -36,7 +36,7 @@ class Grape::Middleware::Logger < Grape::Middleware::Globals
if @app_response.is_a?(Array)
after(@app_response[0])
else
after(@app_response.status)
after(@app_response.status)
end
end
@app_response

View File

@ -49,6 +49,24 @@ describe Grape::Middleware::Logger do
expect(subject.call!(env)).to eq app_response
end
end
context 'when response is an array' do
let(:app_response_array) { Rack::Response.new [401, 'Auth Failed'], 401, {} }
it 'calls +after+ with the correct status' do
expect(app).to receive(:call).with(env).and_return(app_response_array)
expect(subject).to receive(:before)
expect(subject).to receive(:after).with(401)
subject.call!(env)
end
it 'returns the @app_response_array' do
expect(app).to receive(:call).with(env).and_return(app_response_array)
allow(subject).to receive(:before)
allow(subject).to receive(:after)
expect(subject.call!(env)).to eq app_response_array
end
end
end
describe '#after_failure' do