-
Notifications
You must be signed in to change notification settings - Fork 28
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 #48 from ResultadosDigitais/fix-bug-47-handle-html…
…-responses Fix bug 47 handle html responses
- Loading branch information
Showing
6 changed files
with
56 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module RDStation | ||
VERSION = '2.1.0'.freeze | ||
VERSION = '2.1.1'.freeze | ||
end |
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,34 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe RDStation::ApiResponse do | ||
describe ".build" do | ||
context "when the response HTTP status is 2xx" do | ||
let(:response) { OpenStruct.new(code: 200, body: '{}') } | ||
|
||
it "returns the response body" do | ||
expect(RDStation::ApiResponse.build(response)).to eq({}) | ||
end | ||
end | ||
|
||
shared_examples_for 'call_error_handler' do | ||
it "calls error handler" do | ||
error_handler = instance_double(RDStation::ErrorHandler) | ||
allow(error_handler).to receive(:raise_error) | ||
expect(RDStation::ErrorHandler).to receive(:new).with(response).and_return(error_handler) | ||
RDStation::ApiResponse.build(response) | ||
end | ||
end | ||
|
||
context "when the response is not in the 2xx range" do | ||
let(:response) { OpenStruct.new(code: 404, body: '{}') } | ||
|
||
it_behaves_like 'call_error_handler' | ||
end | ||
|
||
context "when the response body is not JSON-parseable" do | ||
let(:response) { OpenStruct.new(code: 504, body: '<html><head></head><body></body></html>') } | ||
|
||
it_behaves_like 'call_error_handler' | ||
end | ||
end | ||
end |
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