Skip to content

Commit

Permalink
Add specs for Grape::DSL::RequestResponse#rescue_from method
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrorius authored and dblock committed Mar 5, 2015
1 parent a9933ca commit 6a7e680
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#### Fixes

* [#936](https://github.com/intridea/grape/pull/936): Fixed default params processing for optional groups - [@dm1try](https://github.com/dm1try).
* [#](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).
* [#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).

* Your contribution here.

Expand Down
64 changes: 62 additions & 2 deletions spec/grape/dsl/request_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,68 @@ def self.imbue(key, value)
end
end

xdescribe '.rescue_from' do
it 'does some thing'
describe '.rescue_from' do
describe ':all' do
it 'sets rescue all to true' do
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, nil)
subject.rescue_from :all
end

it 'sets given proc as rescue handler' do
rescue_handler_proc = proc {}
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, rescue_handler_proc)
subject.rescue_from :all, rescue_handler_proc
end

it 'sets given block as rescue handler' do
rescue_handler_proc = proc {}
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, rescue_handler_proc)
subject.rescue_from :all, &rescue_handler_proc
end

it 'sets a rescue handler declared through :with option' do
expect(subject).to receive(:namespace_inheritable).with(:rescue_all, true)
expect(subject).to receive(:namespace_inheritable).with(:all_rescue_handler, an_instance_of(Proc))
subject.rescue_from :all, with: 'ExampleHandler'
end
end

describe 'list of exceptions is passed' do
it 'sets hash of exceptions as rescue handlers' do
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => nil)
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
subject.rescue_from StandardError
end

it 'rescues only base handlers if rescue_subclasses: false option is passed' do
expect(subject).to receive(:namespace_stackable).with(:base_only_rescue_handlers, StandardError => nil)
expect(subject).to receive(:namespace_stackable).with(:rescue_options, rescue_subclasses: false)
subject.rescue_from StandardError, rescue_subclasses: false
end

it 'sets given proc as rescue handler for each key in hash' do
rescue_handler_proc = proc {}
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
subject.rescue_from StandardError, rescue_handler_proc
end

it 'sets given block as rescue handler for each key in hash' do
rescue_handler_proc = proc {}
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => rescue_handler_proc)
expect(subject).to receive(:namespace_stackable).with(:rescue_options, {})
subject.rescue_from StandardError, &rescue_handler_proc
end

it 'sets a rescue handler declared through :with option for each key in hash' do
expect(subject).to receive(:namespace_stackable).with(:rescue_handlers, StandardError => an_instance_of(Proc))
expect(subject).to receive(:namespace_stackable).with(:rescue_options, with: 'ExampleHandler')
subject.rescue_from StandardError, with: 'ExampleHandler'
end
end
end

describe '.represent' do
Expand Down

0 comments on commit 6a7e680

Please sign in to comment.