-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy patherror_spec.rb
82 lines (70 loc) · 2.24 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
describe Postmates::Error do
let(:client) { postmates_test_client }
let(:customer_id) { client.customer_id }
context 'A request' do
describe 'with invalid parameters' do
let(:params) { {} }
before do
stub_post(path_to('deliveries'),
params.merge(response_code: 400,
returns: 'invalid_params.json'))
end
it 'raises Postmates::BadRequest' do
expect { client.create }
.to raise_error Postmates::BadRequest
end
end
describe 'with incorrect authentication' do
let(:bad_client) { Postmates.new }
before do
stub_get(path_to('deliveries'),
response_code: 401, returns: 'unauthorized.json')
end
it 'raises Postmates::Unauthorized' do
expect { bad_client.list }
.to raise_error Postmates::Unauthorized
end
end
describe 'Forbidden' do
let(:bad_client) { Postmates.new }
before do
stub_get(path_to('deliveries'),
response_code: 403, returns: 'forbidden.json')
end
it 'raises Postmates::Forbidden' do
expect { bad_client.list }
.to raise_error Postmates::Forbidden
end
end
describe 'for a non-existent resource' do
before do
stub_get(path_to('deliveries/bad-id'),
response_code: 404, returns: 'not_found.json')
end
it 'raises Postmates::NotFound' do
expect { client.retrieve('bad-id') }
.to raise_error Postmates::NotFound
end
end
describe 'when there is a problem processing the request' do
before do
stub_get(path_to('deliveries'),
response_code: 500, returns: 'server_error.json')
end
it 'raises Postmates::InternalServerError' do
expect { client.list }
.to raise_error Postmates::InternalServerError
end
end
describe 'when service is unavailable' do
before do
stub_get(path_to('deliveries'),
response_code: 503, returns: 'service_unavailable.json')
end
it 'raises Postmates::ServiceUnavailable' do
expect { client.list }
.to raise_error Postmates::ServiceUnavailable
end
end
end
end