Skip to content

Commit 6a7e680

Browse files
dabroriusdblock
authored andcommitted
Add specs for Grape::DSL::RequestResponse#rescue_from method
1 parent a9933ca commit 6a7e680

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#### Fixes
55

66
* [#936](https://github.com/intridea/grape/pull/936): Fixed default params processing for optional groups - [@dm1try](https://github.com/dm1try).
7-
* [#](https://github.com/intridea/grape/pull/): Fixed forced presence for optional params when based on a reused entity that was also required in another context - [@croeck](https://github.com/croeck).
7+
* [#942](https://github.com/intridea/grape/pull/942): Fixed forced presence for optional params when based on a reused entity that was also required in another context - [@croeck](https://github.com/croeck).
88

99
* Your contribution here.
1010

spec/grape/dsl/request_response_spec.rb

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,68 @@ def self.imbue(key, value)
101101
end
102102
end
103103

104-
xdescribe '.rescue_from' do
105-
it 'does some thing'
104+
describe '.rescue_from' do
105+
describe ':all' do
106+
it 'sets rescue all to true' do
107+
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
108+
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, nil)
109+
subject.rescue_from :all
110+
end
111+
112+
it 'sets given proc as rescue handler' do
113+
rescue_handler_proc = proc {}
114+
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
115+
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, rescue_handler_proc)
116+
subject.rescue_from :all, rescue_handler_proc
117+
end
118+
119+
it 'sets given block as rescue handler' do
120+
rescue_handler_proc = proc {}
121+
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
122+
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, rescue_handler_proc)
123+
subject.rescue_from :all, &rescue_handler_proc
124+
end
125+
126+
it 'sets a rescue handler declared through :with option' do
127+
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
128+
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, an_instance_of(Proc))
129+
subject.rescue_from :all, with: 'ExampleHandler'
130+
end
131+
end
132+
133+
describe 'list of exceptions is passed' do
134+
it 'sets hash of exceptions as rescue handlers' do
135+
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => nil)
136+
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
137+
subject.rescue_from StandardError
138+
end
139+
140+
it 'rescues only base handlers if rescue_subclasses: false option is passed' do
141+
expect(subject).to receive(:namespace_stackable).with(:base_only_rescue_handlers, StandardError => nil)
142+
expect(subject).to receive(:namespace_stackable).with(:rescue_options, rescue_subclasses: false)
143+
subject.rescue_from StandardError, rescue_subclasses: false
144+
end
145+
146+
it 'sets given proc as rescue handler for each key in hash' do
147+
rescue_handler_proc = proc {}
148+
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
149+
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
150+
subject.rescue_from StandardError, rescue_handler_proc
151+
end
152+
153+
it 'sets given block as rescue handler for each key in hash' do
154+
rescue_handler_proc = proc {}
155+
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
156+
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
157+
subject.rescue_from StandardError, &rescue_handler_proc
158+
end
159+
160+
it 'sets a rescue handler declared through :with option for each key in hash' do
161+
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => an_instance_of(Proc))
162+
expect(subject).to receive(:namespace_stackable).with(:rescue_options, with: 'ExampleHandler')
163+
subject.rescue_from StandardError, with: 'ExampleHandler'
164+
end
165+
end
106166
end
107167

108168
describe '.represent' do

0 commit comments

Comments
 (0)