Sha256: 694894436ce0ef06f14775a4a143c1bd5ef2d202b156271cabfa6248620efcd9
Contents?: true
Size: 1.38 KB
Versions: 4
Compression:
Stored size: 1.38 KB
Contents
require 'spec_helper' RSpec.describe RDStation::ErrorHandler do describe '#raise_errors' do subject(:error_handler) { described_class.new(error_response) } context 'when the error type is recognized' do let(:error_response) do OpenStruct.new( code: 400, body: { 'errors' => { 'error_type' => 'CONFLICTING_FIELD', 'error_message' => 'Error Message' } }.to_json ) end it 'raises the corresponding error class' do expect { error_handler.raise_errors }.to raise_error(RDStation::Error::ConflictingField, 'Error Message') end end context 'when the error type is not recognized' do let(:error_response) do OpenStruct.new( code: 400, headers: { 'Content-Type' => 'application/json' }, body: { 'errors' => { 'error_type' => 'UNRECOGNIZED_ERROR_TYPE', 'error_message' => 'Error Message' } }.to_json ) end it 'raises the Default error' do expect { error_handler.raise_errors }.to raise_error(RDStation::Error::Default, 'Error Message') do |error| expect(error.details).to be expect(error.headers).to be expect(error.body).to be expect(error.http_status).to be end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems