Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added spec for expected headers when error raised #1723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions spec/grape/headers_on_error_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'spec_helper'

describe Grape::API do
let(:error_header) do
Class.new(Grape::API) do
before do
header 'X-Grape-Before-Header', '1'
end
after do
header 'X-Grape-After-Header', '1'
end
get '/success' do
header 'X-Grape-Returns-Error', '1'
end
get '/error' do
header 'X-Grape-Returns-Error', '1'
error!(success: false)
end
end
end

subject do
ErrorHeader = error_header unless defined?(ErrorHeader)
Class.new(Grape::API) do
format :json
mount ErrorHeader => '/'
end
end

def app
subject
end

it 'should returns all headers on success' do
get '/success'
expect(last_response.headers['X-Grape-Returns-Error']).to eq('1')
expect(last_response.headers['X-Grape-Before-Header']).to eq('1')
expect(last_response.headers['X-Grape-After-Header']).to eq('1')
end

it 'should returns all headers on error' do
get '/error'
expect(last_response.headers['X-Grape-Returns-Error']).to eq('1')
expect(last_response.headers['X-Grape-Before-Header']).to eq('1')
expect(last_response.headers['X-Grape-After-Header']).to eq('1')
end
end