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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d5577a3a973a53f5d608319d42f2f7bbe764277
4
- data.tar.gz: 3571ca057d566d5c618bca565cb11a255fe0bba8
3
+ metadata.gz: 2087ac52abe5bb2c5c4569bcf8283c11ab8bf211
4
+ data.tar.gz: 1544e7a1465e520b9cd9390e922a02ea93e33348
5
5
  SHA512:
6
- metadata.gz: 9d2c7435085e2359a06036dc9953382644398f59b865ed5a667f55081853873aca86609a16053655a2fb70c029109e0d339720f5278fe973dd623f3e7cdbd58d
7
- data.tar.gz: fa1a182827742a465144c88e9c2e0a0bf8c64481ac8c49e9255452f63f2f2ffd5c9d150c6e3d648929ea7fa7951b813c014e88243e149aa26176858703179889
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
@@ -83,7 +83,8 @@ require 'hobbit/contrib'
83
83
  class App < Hobbit::Base
84
84
  include Hobbit::ErrorHandling
85
85
 
86
- error Exception do |exception|
86
+ error Exception
87
+ exception = env['hobbit.error']
87
88
  exception.message
88
89
  end
89
90
 
@@ -1,5 +1,5 @@
1
1
  module Hobbit
2
2
  module Contrib
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -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
- body = instance_eval { self.class.errors[rescued].call(e) }
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 |exc|
14
- exc.message
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 |exc|
47
- exc.message
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 |exc|
79
- exc.message
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 |exc|
112
- exc.message
114
+ error Exception do
115
+ exception = env['hobbit.error']
116
+ exception.message
113
117
  end
114
118
 
115
119
  before do
@@ -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 |exception|
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(UnknownException)
89
+ proc { get '/uncaught_raise' }.must_raise UnknownException
80
90
  end
81
91
  end
82
92
 
83
- describe 'when raises an known exception class' do
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
- let(:app) do
8
- mock_app do
9
- include Hobbit::Filter
7
+ describe 'basic specs' do
8
+ let(:app) do
9
+ mock_app do
10
+ include Hobbit::Filter
10
11
 
11
- before do
12
- env['hobbit.before'] = 'this is before'
13
- end
12
+ before do
13
+ env['hobbit.before'] = 'this is before'
14
+ end
14
15
 
15
- get '/' do
16
- 'GET /'
17
- end
16
+ get '/' do
17
+ 'GET /'
18
+ end
18
19
 
19
- after do
20
- env['hobbit.after'] = 'this is after'
20
+ after do
21
+ env['hobbit.after'] = 'this is after'
22
+ end
21
23
  end
22
24
  end
23
- end
24
25
 
25
- %w(after before).each do |kind|
26
- str = <<EOS
27
- describe '::#{kind}' do
28
- specify do
29
- p = Proc.new { 'do something' }
30
- app = mock_app do
31
- include Hobbit::Filter
32
- #{kind}('', &p)
33
- end
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
- app.to_app.class.filters[:#{kind}].size.must_equal 1
36
- app.to_app.class.filters[:#{kind}].first[:block].call.must_equal p.call
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
- describe 'when a filter matches' do
41
- it "must call the filters' block" do
42
- get '/'
43
- last_response.must_be :ok?
44
- last_request.env.must_include 'hobbit.#{kind}'
45
- last_request.env['hobbit.#{kind}'].must_equal 'this is #{kind}'
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
- class_eval str
50
- end
50
+ class_eval str
51
+ end
51
52
 
52
- describe '::filters' do
53
- it 'must return a Hash' do
54
- app.to_app.class.filters.must_be_kind_of Hash
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
- describe '::compile_filter' do
59
- let(:block) { block = Proc.new { |env| [200, {}, []] } }
59
+ describe '::compile_filter' do
60
+ let(:block) { block = Proc.new { |env| [200, {}, []] } }
60
61
 
61
- it 'must compile /' do
62
- path = '/'
63
- route = app.to_app.class.send :compile_filter, path, &block
64
- route[:block].call({}).must_equal block.call({})
65
- route[:compiled_path].to_s.must_equal /^\/$/.to_s
66
- end
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
- it 'must compile with .' do
69
- path = '/route.json'
70
- route = app.to_app.class.send :compile_filter, path, &block
71
- route[:block].call({}).must_equal block.call({})
72
- route[:compiled_path].to_s.must_equal /^\/route.json$/.to_s
73
- end
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
- it 'must compile with -' do
76
- path = '/hello-world'
77
- route = app.to_app.class.send :compile_filter, path, &block
78
- route[:block].call({}).must_equal block.call({})
79
- route[:compiled_path].to_s.must_equal /^\/hello-world$/.to_s
80
- end
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
- it 'must compile with params' do
83
- path = '/hello/:name'
84
- route = app.to_app.class.send :compile_filter, path, &block
85
- route[:block].call({}).must_equal block.call({})
86
- route[:compiled_path].to_s.must_equal /^\/hello\/([^\/?#]+)$/.to_s
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
- path = '/say/:something/to/:someone'
89
- route = app.to_app.class.send :compile_filter, path, &block
90
- route[:block].call({}).must_equal block.call({})
91
- route[:compiled_path].to_s.must_equal /^\/say\/([^\/?#]+)\/to\/([^\/?#]+)$/.to_s
92
- end
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
- it 'must compile with . and params' do
95
- path = '/route/:id.json'
96
- route = app.to_app.class.send :compile_filter, path, &block
97
- route[:block].call({}).must_equal block.call({})
98
- route[:compiled_path].to_s.must_equal /^\/route\/([^\/?#]+).json$/.to_s
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
- it 'must call before and after filters' do
103
- get '/'
104
- last_response.must_be :ok?
105
- last_request.env.must_include 'hobbit.before'
106
- last_request.env['hobbit.before'].must_equal 'this is before'
107
- last_request.env.must_include 'hobbit.after'
108
- last_request.env['hobbit.after'].must_equal 'this is after'
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.0
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-01-11 00:00:00.000000000 Z
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.1
178
+ rubygems_version: 2.2.0
179
179
  signing_key:
180
180
  specification_version: 4
181
181
  summary: Contributed Hobbit extensions