hobbit-contrib 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -1
- data/lib/hobbit/contrib/version.rb +1 -1
- data/lib/hobbit/error_handling.rb +2 -1
- data/spec/error_handling_and_filter_spec.rb +12 -8
- data/spec/error_handling_spec.rb +20 -3
- data/spec/filter_spec.rb +82 -80
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2087ac52abe5bb2c5c4569bcf8283c11ab8bf211
|
4
|
+
data.tar.gz: 1544e7a1465e520b9cd9390e922a02ea93e33348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f02bf743b5869c1d812ac4ea6063931d7c7165d725e1f9a778738c67689c548a456cd32dbffc955cbe42df2d9c4f5de5ba9f7cb734f07674e90d2e095b60c82
|
7
|
+
data.tar.gz: 4737a3d1692bbc5b180d327142d818ae0383b9cfae21db88bbbb7c5707e43500eb2aeb76f25527cd7433a9995ed5defd0d1bc4c8614a98067447c1b34dfe39e0
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.4.1
|
2
|
+
|
3
|
+
* Fix `Hobbit::ErrorHandling`. Now, when an exception is raised, the `error`
|
4
|
+
block is executed in the context of the object, not the class.
|
5
|
+
* Fix error handling and filter specs.
|
6
|
+
|
1
7
|
# 0.4.0
|
2
8
|
|
3
9
|
* Fix `Hobbit::Filter`. Now it works with `halt`, introduced in `hobbit` 0.4.0.
|
data/README.md
CHANGED
@@ -15,7 +15,8 @@ module Hobbit
|
|
15
15
|
rescue *self.class.errors.keys => e
|
16
16
|
rescued = self.class.errors.keys.detect { |k| e.kind_of?(k) }
|
17
17
|
|
18
|
-
|
18
|
+
env['hobbit.error'] = e
|
19
|
+
body = instance_eval &self.class.errors[rescued]
|
19
20
|
response.body = [body]
|
20
21
|
response.finish
|
21
22
|
end
|
@@ -10,8 +10,9 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
10
10
|
include Hobbit::Filter
|
11
11
|
include Hobbit::ErrorHandling
|
12
12
|
|
13
|
-
error Exception do
|
14
|
-
|
13
|
+
error Exception do
|
14
|
+
exception = env['hobbit.error']
|
15
|
+
exception.message
|
15
16
|
end
|
16
17
|
|
17
18
|
before do
|
@@ -43,8 +44,9 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
43
44
|
include Hobbit::Filter
|
44
45
|
include Hobbit::ErrorHandling
|
45
46
|
|
46
|
-
error Exception do
|
47
|
-
|
47
|
+
error Exception do
|
48
|
+
exception = env['hobbit.error']
|
49
|
+
exception.message
|
48
50
|
end
|
49
51
|
|
50
52
|
before do
|
@@ -75,8 +77,9 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
75
77
|
include Hobbit::Filter
|
76
78
|
include Hobbit::ErrorHandling
|
77
79
|
|
78
|
-
error Exception do
|
79
|
-
|
80
|
+
error Exception do
|
81
|
+
exception = env['hobbit.error']
|
82
|
+
exception.message
|
80
83
|
end
|
81
84
|
|
82
85
|
before do
|
@@ -108,8 +111,9 @@ describe 'combine Hobbit::ErrorHandling and Hobbit::Filter' do
|
|
108
111
|
include Hobbit::ErrorHandling
|
109
112
|
include Hobbit::Filter
|
110
113
|
|
111
|
-
error Exception do
|
112
|
-
|
114
|
+
error Exception do
|
115
|
+
exception = env['hobbit.error']
|
116
|
+
exception.message
|
113
117
|
end
|
114
118
|
|
115
119
|
before do
|
data/spec/error_handling_spec.rb
CHANGED
@@ -7,6 +7,7 @@ describe Hobbit::ErrorHandling do
|
|
7
7
|
class NotFoundException < Exception ; end
|
8
8
|
class SpecificNotFoundException < NotFoundException ; end
|
9
9
|
class UnknownException < Exception ; end
|
10
|
+
class MustUseResponseException < Exception ; end
|
10
11
|
|
11
12
|
let(:app) do
|
12
13
|
mock_app do
|
@@ -16,10 +17,14 @@ describe Hobbit::ErrorHandling do
|
|
16
17
|
'Not Found'
|
17
18
|
end
|
18
19
|
|
19
|
-
error StandardError do
|
20
|
+
error StandardError do
|
21
|
+
exception = env['hobbit.error']
|
20
22
|
exception.message
|
21
23
|
end
|
22
24
|
|
25
|
+
error MustUseResponseException do
|
26
|
+
response.redirect '/'
|
27
|
+
end
|
23
28
|
|
24
29
|
get '/' do
|
25
30
|
'hello'
|
@@ -44,6 +49,11 @@ describe Hobbit::ErrorHandling do
|
|
44
49
|
response.write 'not this'
|
45
50
|
raise UnknownException
|
46
51
|
end
|
52
|
+
|
53
|
+
get '/must_use_response' do
|
54
|
+
response.write 'not this'
|
55
|
+
raise MustUseResponseException
|
56
|
+
end
|
47
57
|
end
|
48
58
|
end
|
49
59
|
|
@@ -76,11 +86,11 @@ describe Hobbit::ErrorHandling do
|
|
76
86
|
|
77
87
|
describe 'when does raise an unknown exception class' do
|
78
88
|
it 'must not halt default propagation of the unknown class' do
|
79
|
-
proc {get '/uncaught_raise'}.must_raise
|
89
|
+
proc { get '/uncaught_raise' }.must_raise UnknownException
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
83
|
-
describe 'when raises
|
93
|
+
describe 'when raises a known exception class' do
|
84
94
|
it 'must call the block set in error' do
|
85
95
|
get '/raises'
|
86
96
|
last_response.must_be :ok?
|
@@ -115,5 +125,12 @@ describe Hobbit::ErrorHandling do
|
|
115
125
|
last_response.must_be :ok?
|
116
126
|
last_response.body.must_equal 'other handler!'
|
117
127
|
end
|
128
|
+
|
129
|
+
it 'must use response object' do
|
130
|
+
get '/must_use_response'
|
131
|
+
last_response.must_be :redirection?
|
132
|
+
follow_redirect!
|
133
|
+
last_response.body.must_equal 'hello'
|
134
|
+
end
|
118
135
|
end
|
119
136
|
end
|
data/spec/filter_spec.rb
CHANGED
@@ -4,108 +4,110 @@ describe Hobbit::Filter do
|
|
4
4
|
include Hobbit::Contrib::Mock
|
5
5
|
include Rack::Test::Methods
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
describe 'basic specs' do
|
8
|
+
let(:app) do
|
9
|
+
mock_app do
|
10
|
+
include Hobbit::Filter
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
before do
|
13
|
+
env['hobbit.before'] = 'this is before'
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
get '/' do
|
17
|
+
'GET /'
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
20
|
+
after do
|
21
|
+
env['hobbit.after'] = 'this is after'
|
22
|
+
end
|
21
23
|
end
|
22
24
|
end
|
23
|
-
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
%w(after before).each do |kind|
|
27
|
+
str = <<EOS
|
28
|
+
describe '::#{kind}' do
|
29
|
+
specify do
|
30
|
+
p = Proc.new { 'do something' }
|
31
|
+
app = mock_app do
|
32
|
+
include Hobbit::Filter
|
33
|
+
#{kind}('', &p)
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
app.to_app.class.filters[:#{kind}].size.must_equal 1
|
37
|
+
app.to_app.class.filters[:#{kind}].first[:block].call.must_equal p.call
|
38
|
+
end
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
41
|
+
describe 'when a filter matches' do
|
42
|
+
it "must call the filters' block" do
|
43
|
+
get '/'
|
44
|
+
last_response.must_be :ok?
|
45
|
+
last_request.env.must_include 'hobbit.#{kind}'
|
46
|
+
last_request.env['hobbit.#{kind}'].must_equal 'this is #{kind}'
|
47
|
+
end
|
46
48
|
end
|
47
|
-
end
|
48
49
|
EOS
|
49
|
-
|
50
|
-
|
50
|
+
class_eval str
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
describe '::filters' do
|
54
|
+
it 'must return a Hash' do
|
55
|
+
app.to_app.class.filters.must_be_kind_of Hash
|
56
|
+
end
|
55
57
|
end
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
describe '::compile_filter' do
|
60
|
+
let(:block) { block = Proc.new { |env| [200, {}, []] } }
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
it 'must compile /' do
|
63
|
+
path = '/'
|
64
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
65
|
+
route[:block].call({}).must_equal block.call({})
|
66
|
+
route[:compiled_path].to_s.must_equal /^\/$/.to_s
|
67
|
+
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
it 'must compile with .' do
|
70
|
+
path = '/route.json'
|
71
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
72
|
+
route[:block].call({}).must_equal block.call({})
|
73
|
+
route[:compiled_path].to_s.must_equal /^\/route.json$/.to_s
|
74
|
+
end
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
it 'must compile with -' do
|
77
|
+
path = '/hello-world'
|
78
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
79
|
+
route[:block].call({}).must_equal block.call({})
|
80
|
+
route[:compiled_path].to_s.must_equal /^\/hello-world$/.to_s
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
83
|
+
it 'must compile with params' do
|
84
|
+
path = '/hello/:name'
|
85
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
86
|
+
route[:block].call({}).must_equal block.call({})
|
87
|
+
route[:compiled_path].to_s.must_equal /^\/hello\/([^\/?#]+)$/.to_s
|
87
88
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
89
|
+
path = '/say/:something/to/:someone'
|
90
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
91
|
+
route[:block].call({}).must_equal block.call({})
|
92
|
+
route[:compiled_path].to_s.must_equal /^\/say\/([^\/?#]+)\/to\/([^\/?#]+)$/.to_s
|
93
|
+
end
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
95
|
+
it 'must compile with . and params' do
|
96
|
+
path = '/route/:id.json'
|
97
|
+
route = app.to_app.class.send :compile_filter, path, &block
|
98
|
+
route[:block].call({}).must_equal block.call({})
|
99
|
+
route[:compiled_path].to_s.must_equal /^\/route\/([^\/?#]+).json$/.to_s
|
100
|
+
end
|
99
101
|
end
|
100
|
-
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
103
|
+
it 'must call before and after filters' do
|
104
|
+
get '/'
|
105
|
+
last_response.must_be :ok?
|
106
|
+
last_request.env.must_include 'hobbit.before'
|
107
|
+
last_request.env['hobbit.before'].must_equal 'this is before'
|
108
|
+
last_request.env.must_include 'hobbit.after'
|
109
|
+
last_request.env['hobbit.after'].must_equal 'this is after'
|
110
|
+
end
|
109
111
|
end
|
110
112
|
|
111
113
|
describe 'when multiple filters are declared' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hobbit-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricio Mac Adden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
requirements: []
|
177
177
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.2.
|
178
|
+
rubygems_version: 2.2.0
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: Contributed Hobbit extensions
|