-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from mattbeedle/fix-errors
Fix errors
- Loading branch information
Showing
5 changed files
with
115 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'spec_helper' | ||
|
||
describe CapsuleCRM::Errors do | ||
describe '.error_from_env' do | ||
let(:env) { OpenStruct.new(body: { message: 'test' }.to_json) } | ||
|
||
subject { described_class.error_from_env(env) } | ||
|
||
context 'with a 400 response' do | ||
before { env.status = 400 } | ||
|
||
it 'should return a bad request error' do | ||
expect(subject).to be_a(CapsuleCRM::Errors::BadRequest) | ||
end | ||
end | ||
|
||
context 'with a 401 response' do | ||
before { env.status = 401 } | ||
|
||
it 'should return a not authorized error' do | ||
expect(subject).to be_a(CapsuleCRM::Errors::NotAuthorized) | ||
end | ||
end | ||
|
||
context 'with a 404 response' do | ||
before { env.status = 404 } | ||
|
||
it 'should return a not found error' do | ||
expect(subject).to be_a(CapsuleCRM::Errors::NotFound) | ||
end | ||
end | ||
|
||
context 'with a 500 response' do | ||
before { env.status = 500 } | ||
|
||
it 'should return a internal server error' do | ||
expect(subject).to be_a(CapsuleCRM::Errors::InternalServerError) | ||
end | ||
end | ||
end | ||
end |
59 changes: 59 additions & 0 deletions
59
spec/lib/capsule_crm/faraday/middleware/raise_error_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe CapsuleCRM::Faraday::Middleware::RaiseError do | ||
describe '#on_complete' do | ||
subject { described_class.new } | ||
|
||
context 'when the response is a success' do | ||
let(:response) { Hash[status: 200] } | ||
|
||
it 'should return nothing' do | ||
expect(subject.on_complete(response)).to eql(nil) | ||
end | ||
end | ||
|
||
context 'when the response is a 400' do | ||
let(:response) do | ||
OpenStruct.new(status: 400, body: { message: 'test' }.to_json) | ||
end | ||
|
||
it 'should raise a bad request error' do | ||
expect { subject.on_complete(response) }. | ||
to raise_error(CapsuleCRM::Errors::BadRequest) | ||
end | ||
end | ||
|
||
context 'when the response is a 401' do | ||
let(:response) do | ||
OpenStruct.new(status: 401, body: { message: 'test' }.to_json) | ||
end | ||
|
||
it 'should raise a not authorized error' do | ||
expect { subject.on_complete(response) }. | ||
to raise_error(CapsuleCRM::Errors::NotAuthorized) | ||
end | ||
end | ||
|
||
context 'when the response is a 404' do | ||
let(:response) do | ||
OpenStruct.new(status: 404, body: { message: 'test' }.to_json) | ||
end | ||
|
||
it 'should raise a not found error' do | ||
expect { subject.on_complete(response) }. | ||
to raise_error(CapsuleCRM::Errors::NotFound) | ||
end | ||
end | ||
|
||
context 'when the response is a 500' do | ||
let(:response) do | ||
OpenStruct.new(status: 500, body: { message: 'test' }.to_json) | ||
end | ||
|
||
it 'should raise an internal server error' do | ||
expect { subject.on_complete(response) }. | ||
to raise_error(CapsuleCRM::Errors::InternalServerError) | ||
end | ||
end | ||
end | ||
end |