Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit ef6d2fc

Browse files
committed
Ensure that errors captured by rescue_from are not allowed to bubble up
to code examples. [#85]
1 parent e98e0c7 commit ef6d2fc

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

lib/spec/rails/extensions/action_controller/rescue.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ def use_rails_error_handling?
88
@use_rails_error_handling ||= false
99
end
1010

11-
protected
11+
protected
12+
1213
def rescue_action_with_fast_errors(exception)
13-
if use_rails_error_handling?
14-
rescue_action_without_fast_errors exception
15-
else
16-
raise exception
14+
unless rescue_with_handler(exception)
15+
if use_rails_error_handling?
16+
rescue_action_without_fast_errors exception
17+
else
18+
raise exception
19+
end
1720
end
1821
end
1922
alias_method_chain :rescue_action, :fast_errors
23+
2024
end
2125
end

spec/resources/controllers/controller_spec_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def action_that_assigns_false_to_a_variable
8888
end
8989

9090
class RescuedError < Exception; end
91-
class OtherError < Exception; end
91+
class UnRescuedError < Exception; end
9292
rescue_from RescuedError do |e|
9393
render :text => 'Rescued!'
9494
end
@@ -98,7 +98,7 @@ def rescued_error_action
9898
end
9999

100100
def other_error_action
101-
raise OtherError
101+
raise UnRescuedError
102102
end
103103

104104
end

spec/spec/rails/example/controller_spec_spec.rb

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,23 +159,51 @@
159159
end
160160

161161
describe "with an error that is not rescued in the controller" do
162-
it "should raise the error" do
163-
lambda do
164-
get 'other_error_action'
165-
end.should raise_error(ControllerSpecController::OtherError)
162+
context "without rails' error handling" do
163+
it "raises the error" do
164+
lambda do
165+
get 'other_error_action'
166+
end.should raise_error(ControllerSpecController::UnRescuedError)
167+
end
168+
end
169+
context "with rails' error handling" do
170+
it "does not raise the error" do
171+
controller.use_rails_error_handling!
172+
lambda do
173+
get 'other_error_action'
174+
end.should_not raise_error
175+
end
166176
end
167177
end
168178

169179
describe "with an error that is rescued in the controller" do
170-
it "should not raise error" do
171-
lambda do
180+
context "without rails' error handling" do
181+
it "does not raise error" do
182+
lambda do
183+
get 'rescued_error_action'
184+
end.should_not raise_error
185+
end
186+
187+
it "executes rescue_from" do
172188
get 'rescued_error_action'
173-
end.should_not raise_error
189+
response.body.should == 'Rescued!'
190+
end
174191
end
175192

176-
it "should execute rescue_from" do
177-
get 'rescued_error_action'
178-
response.body.should == 'Rescued!'
193+
context "with rails' error handling" do
194+
before(:each) do
195+
controller.use_rails_error_handling!
196+
end
197+
it "does not raise error" do
198+
lambda do
199+
get 'rescued_error_action'
200+
end.should_not raise_error
201+
end
202+
203+
it "executes rescue_from" do
204+
get 'rescued_error_action'
205+
response.body.should == 'Rescued!'
206+
end
179207
end
180208
end
181209

0 commit comments

Comments
 (0)