Skip to content

Commit a510ada

Browse files
committed
Add spec for service errors when parsing varying response body.
1 parent 2bc6c69 commit a510ada

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Error::ServiceError do
6+
let(:user) { 'peter-murach' }
7+
let(:repo) { 'github' }
8+
9+
def test_request(body='')
10+
stub_get("/repos/#{user}/#{repo}/branches").
11+
to_return(:body => body, :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
12+
end
13+
14+
it "handles empty message" do
15+
test_request
16+
expect {
17+
Github.repos.branches user, repo
18+
}.to raise_error(Github::Error::NotFound)
19+
end
20+
21+
it "handles error message" do
22+
test_request :error => 'not found'
23+
expect {
24+
Github.repos.branches user, repo
25+
}.to raise_error(Github::Error::NotFound, /not found/)
26+
end
27+
28+
it "handles nested errors" do
29+
test_request :errors => { :message => 'key is already in use' }
30+
expect {
31+
Github.repos.branches user, repo
32+
}.to raise_error(Github::Error::NotFound, /key is already in use/)
33+
end
34+
35+
it 'decodes message' do
36+
test_request MultiJson.dump(:errors => { :message => 'key is already in use' })
37+
expect {
38+
Github.repos.branches user, repo
39+
}.to raise_error(Github::Error::NotFound, /key is already in use/)
40+
end
41+
42+
43+
end # Github::Error::ServiceError

0 commit comments

Comments
 (0)