|
6 | 6 | let(:dummy_class) do |
7 | 7 | Class.new do |
8 | 8 | extend Grape::DSL::RequestResponse |
9 | | - |
10 | | - def self.namespace_stackable_with_hash(_key) |
11 | | - {} |
12 | | - end |
13 | | - |
14 | | - def self.namespace_stackable(key, value = nil) |
15 | | - if value |
16 | | - namespace_stackable_hash[key] << value |
17 | | - else |
18 | | - namespace_stackable_hash[key] |
19 | | - end |
20 | | - end |
21 | | - |
22 | | - def self.namespace_inheritable(key, value = nil) |
23 | | - if value |
24 | | - namespace_inheritable_hash[key] = value |
25 | | - else |
26 | | - namespace_inheritable_hash[key] |
27 | | - end |
28 | | - end |
29 | | - |
30 | | - def self.namespace_stackable_hash |
31 | | - @namespace_stackable_hash ||= Hash.new do |hash, key| |
32 | | - hash[key] = [] |
33 | | - end |
34 | | - end |
35 | | - |
36 | | - def self.namespace_inheritable_hash |
37 | | - @namespace_inheritable_hash ||= {} |
38 | | - end |
| 9 | + extend Grape::DSL::Settings |
39 | 10 | end |
40 | 11 | end |
41 | 12 |
|
@@ -147,7 +118,7 @@ def self.namespace_inheritable_hash |
147 | 118 | it 'sets a rescue handler declared through :with option' do |
148 | 119 | with_block = -> { 'hello' } |
149 | 120 | expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true) |
150 | | - expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, an_instance_of(Proc)) |
| 121 | + expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, with_block) |
151 | 122 | subject.rescue_from :all, with: with_block |
152 | 123 | end |
153 | 124 |
|
@@ -192,43 +163,43 @@ def self.namespace_inheritable_hash |
192 | 163 | with_block = -> { 'hello' } |
193 | 164 | expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true) |
194 | 165 | expect(subject).to receive(:namespace_inheritable).with(:rescue_grape_exceptions, true) |
195 | | - expect(subject).to receive(:namespace_inheritable).with(:grape_exceptions_rescue_handler, an_instance_of(Proc)) |
| 166 | + expect(subject).to receive(:namespace_inheritable).with(:grape_exceptions_rescue_handler, with_block) |
196 | 167 | subject.rescue_from :grape_exceptions, with: with_block |
197 | 168 | end |
198 | 169 | end |
199 | 170 |
|
200 | 171 | describe 'list of exceptions is passed' do |
201 | 172 | it 'sets hash of exceptions as rescue handlers' do |
202 | | - expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => nil }) |
203 | 173 | expect(subject).to receive(:namespace_stackable).with(:rescue_options, {}) |
204 | 174 | subject.rescue_from StandardError |
| 175 | + expect(subject.inheritable_setting.namespace_reverse_stackable[:rescue_handlers]).to eq([StandardError => nil]) |
205 | 176 | end |
206 | 177 |
|
207 | 178 | it 'rescues only base handlers if rescue_subclasses: false option is passed' do |
208 | | - expect(subject).to receive(:namespace_reverse_stackable).with(:base_only_rescue_handlers, { StandardError => nil }) |
209 | 179 | expect(subject).to receive(:namespace_stackable).with(:rescue_options, { rescue_subclasses: false }) |
210 | 180 | subject.rescue_from StandardError, rescue_subclasses: false |
| 181 | + expect(subject.inheritable_setting.namespace_reverse_stackable[:base_only_rescue_handlers]).to eq([StandardError => nil]) |
211 | 182 | end |
212 | 183 |
|
213 | 184 | it 'sets given proc as rescue handler for each key in hash' do |
214 | 185 | rescue_handler_proc = proc {} |
215 | | - expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => rescue_handler_proc }) |
216 | 186 | expect(subject).to receive(:namespace_stackable).with(:rescue_options, {}) |
217 | 187 | subject.rescue_from StandardError, rescue_handler_proc |
| 188 | + expect(subject.inheritable_setting.namespace_reverse_stackable[:rescue_handlers]).to eq([StandardError => rescue_handler_proc]) |
218 | 189 | end |
219 | 190 |
|
220 | 191 | it 'sets given block as rescue handler for each key in hash' do |
221 | 192 | rescue_handler_proc = proc {} |
222 | | - expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => rescue_handler_proc }) |
223 | 193 | expect(subject).to receive(:namespace_stackable).with(:rescue_options, {}) |
224 | 194 | subject.rescue_from StandardError, &rescue_handler_proc |
| 195 | + expect(subject.inheritable_setting.namespace_reverse_stackable[:rescue_handlers]).to eq([StandardError => rescue_handler_proc]) |
225 | 196 | end |
226 | 197 |
|
227 | 198 | it 'sets a rescue handler declared through :with option for each key in hash' do |
228 | 199 | with_block = -> { 'hello' } |
229 | | - expect(subject).to receive(:namespace_reverse_stackable).with(:rescue_handlers, { StandardError => an_instance_of(Proc) }) |
230 | 200 | expect(subject).to receive(:namespace_stackable).with(:rescue_options, {}) |
231 | 201 | subject.rescue_from StandardError, with: with_block |
| 202 | + expect(subject.inheritable_setting.namespace_reverse_stackable[:rescue_handlers]).to eq([StandardError => with_block]) |
232 | 203 | end |
233 | 204 | end |
234 | 205 | end |
|
0 commit comments