gh 0.10.3 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gh/error.rb +9 -0
- data/lib/gh/version.rb +1 -1
- data/spec/error_spec.rb +19 -0
- metadata +2 -2
data/lib/gh/error.rb
CHANGED
@@ -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
|
data/lib/gh/version.rb
CHANGED
data/spec/error_spec.rb
CHANGED
@@ -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.
|
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-
|
12
|
+
date: 2013-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|