-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathheaders_on_error_spec.rb
47 lines (42 loc) · 1.17 KB
/
headers_on_error_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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