spec/client_spec.rb in phaxio-2.1.0 vs spec/client_spec.rb in phaxio-2.1.1
- old
+ new
@@ -17,10 +17,20 @@
headers: {content_type: 'application/json'},
body: %Q({"success": #{success}, "message": "#{message}", "data": {"foo": "bar"}})
)
end
+ def test_response_503
+ instance_double(
+ Faraday::Response,
+ status: 503,
+ success?: false,
+ headers: {},
+ body: nil
+ )
+ end
+
describe 'making a request' do
it 'sends the request to Phaxio' do
endpoint = 'public/countries/'
params = {page: 1, per_page: 10}
expect(test_connection).to receive(:get) do |request_endpoint, request_params|
@@ -114,9 +124,16 @@
it 'raises a rate limit error if the response status is 429' do
expect(test_connection).to receive(:get) { test_response 429 }
expect {
client.request :get, 'test'
}.to raise_error(Phaxio::Error::RateLimitExceededError, '429: This is a test.')
+ end
+
+ it 'raises a service unavailable error if the response status is 503' do
+ expect(test_connection).to receive(:get) { test_response_503 }
+ expect {
+ client.request :get, 'test'
+ }.to raise_error(Phaxio::Error::ServiceUnavailableError, '503: ')
end
it 'raises a general error for if the response status is 5XX' do
expect(test_connection).to receive(:get) { test_response 500 }
expect {