gh 0.10.3 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -52,4 +52,13 @@ module GH
52
52
 
53
53
  class TokenInvalid < Error
54
54
  end
55
+
56
+ def self.Error(conditions)
57
+ Module.new do
58
+ define_singleton_method(:===) do |exception|
59
+ return false unless Error === exception and not exception.info.nil?
60
+ conditions.all? { |k,v| v === exception.info[k]}
61
+ end
62
+ end
63
+ end
55
64
  end
@@ -1,4 +1,4 @@
1
1
  module GH
2
2
  # Public: Library version.
3
- VERSION = "0.10.3"
3
+ VERSION = "0.11.0"
4
4
  end
@@ -33,4 +33,23 @@ describe GH::Error do
33
33
  error = GH::Error.new(nil, nil, 'foo' => 'a'*1000)
34
34
  expect { error.message }.not_to raise_error
35
35
  end
36
+
37
+ it 'can be rescued by status code' do
38
+ stub_request(:get, "https://api.github.com/missing").to_return(:status => 404)
39
+
40
+ expect do
41
+ begin
42
+ GH['missing']
43
+ rescue GH::Error(:response_status => 404)
44
+ end
45
+ end.not_to raise_error
46
+
47
+
48
+ expect do
49
+ begin
50
+ GH['missing']
51
+ rescue GH::Error(:response_status => 500)
52
+ end
53
+ end.to raise_error(GH::Error)
54
+ end
36
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.3
4
+ version: 0.11.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-22 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec