tag' do
let(:response_body) { 'Well, this is unexpected!' }
it 'should raise an UnknownError' do
expect{ subject.post_request('do_something', request_params) }.to raise_error(UplandMobileCommonsRest::UnknownError)
end
end
context 'response body with success=true' do
let(:response_body) { 'hurray!' }
it 'should not raise' do
expect{ subject.post_request('do_something', request_params) }.not_to raise_error
end
end
include_examples 'error code parsing'
end
context '400 status response' do
let(:response_status) { 400 }
include_examples 'error code parsing'
end
context '502 status response' do
let(:response_status) { 502 }
let(:response_body) { '502 Bad Gateway502 Bad Gateway
' }
it 'should raise an BadGatewayError' do
expect do
subject.post_request('do_something', request_params)
end.to raise_error(UplandMobileCommonsRest::BadGatewayError) do |error|
expect(error.body).to eq response_body
expect(error.to_s).to include(response_body)
end
end
end
context '503 status response' do
let(:response_status) { 503 }
let(:response_body) { '503 Internal Server Error503 Internal Server Error
' }
it 'should raise an UnknownError' do
expect do
subject.post_request('do_something', request_params)
end.to raise_error(UplandMobileCommonsRest::UnknownError) do |error|
expect(error.to_s).to include(response_body)
end
end
context 'with Heavy Load message' do
let(:response_body) { "This website is under heavy load (queue full)
We're sorry, too many people are accessing this website at the same time. We're working on this problem. Please try again later.
" }
it 'should raise a HeavyLoadError' do
expect do
subject.post_request('do_something', request_params)
end.to raise_error(UplandMobileCommonsRest::HeavyLoadError) do |error|
expect(error.to_s).to include(response_body)
end
end
end
context 'with Site Maintenance message' do
let(:response_body) { "Site MaintenanceSorry for the inconvenience but we're performing some maintenance at the moment. If you need to you can always contact us, otherwise we'll be back online shortly!
" }
it 'should raise a SiteMaintenanceError' do
expect do
subject.post_request('do_something', request_params)
end.to raise_error(UplandMobileCommonsRest::SiteMaintenanceError) do |error|
expect(error.to_s).to include(response_body)
end
end
end
end
context '504 status response' do
let(:response_status) { 504 }
let(:response_body) { '504 Gateway Time-out504 Gateway Time-out
' }
it 'should raise an GatewayTimeoutError' do
expect do
subject.post_request('do_something', request_params)
end.to raise_error(UplandMobileCommonsRest::GatewayTimeoutError) do |error|
expect(error.body).to eq response_body
expect(error.to_s).to include(response_body)
end
end
end
end
end