Skip to content

Commit

Permalink
use strings instead of symbols, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amro committed May 20, 2014
1 parent 609a6c9 commit 59d4dd0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/gibbon/api_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def call(method, params = {})
parsed_response = MultiJson.load(response.body)
rescue MultiJson::ParseError
parsed_response = {
error: "Unparseable response: #{response.body}",
name: "UNPARSEABLE_RESPONSE",
code: 500
"error" => "Unparseable response: #{response.body}",
"name" => "UNPARSEABLE_RESPONSE",
"code" => 500
}
end

Expand Down
12 changes: 12 additions & 0 deletions spec/gibbon/gibbon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new(MultiJson.dump({"cid" => "1234567"})))
expect(@gibbon.campaigns.send({"cid" => "1234567"})).to eq({"cid" => "1234567"})
end

it "not throw exception if configured to and the API returns an unparsable response" do
@gibbon.throws_exceptions = false
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new("<HTML>Invalid response</HTML>"))
expect(@gibbon.say.hello).to eq({"name" => "UNPARSEABLE_RESPONSE", "error" => "Unparseable response: <HTML>Invalid response</HTML>", "code" => 500})
end

it "throw exception if configured to and the API returns an unparsable response" do
@gibbon.throws_exceptions = true
allow(Gibbon::APICategory).to receive(:post).and_return(Struct.new(:body).new("<HTML>Invalid response</HTML>"))
expect{@gibbon.say.hello}.to raise_error(Gibbon::MailChimpError)
end
end

describe "export API" do
Expand Down

0 comments on commit 59d4dd0

Please sign in to comment.