forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice_error_spec.rb
More file actions
43 lines (34 loc) · 1.16 KB
/
service_error_spec.rb
File metadata and controls
43 lines (34 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# encoding: utf-8
require 'spec_helper'
describe Github::Error::ServiceError do
let(:user) { 'peter-murach' }
let(:repo) { 'github' }
def test_request(body='')
stub_get("/repos/#{user}/#{repo}/branches").
to_return(:body => body, :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
end
it "handles empty message" do
test_request
expect {
Github.repos.branches user, repo
}.to raise_error(Github::Error::NotFound)
end
it "handles error message" do
test_request :error => 'not found'
expect {
Github.repos.branches user, repo
}.to raise_error(Github::Error::NotFound, /not found/)
end
it "handles nested errors" do
test_request :errors => { :message => 'key is already in use' }
expect {
Github.repos.branches user, repo
}.to raise_error(Github::Error::NotFound, /key is already in use/)
end
it 'decodes message' do
test_request MultiJson.dump(:errors => { :message => 'key is already in use' })
expect {
Github.repos.branches user, repo
}.to raise_error(Github::Error::NotFound, /key is already in use/)
end
end # Github::Error::ServiceError