aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/rescuable_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-16 20:21:01 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-16 20:21:01 -0200
commite4c9bd9828e107214d03a66679a89f669e3722fa (patch)
tree050d720a99118f9b35715bc5bf5111bfc73f783e /activesupport/test/rescuable_test.rb
parent8c11c23267e8218ef49b2533fda7dd76ab9fbeac (diff)
parentdd96e8e3337c04c5c37ece7983d012a9353804ac (diff)
downloadrails-e4c9bd9828e107214d03a66679a89f669e3722fa.tar.gz
rails-e4c9bd9828e107214d03a66679a89f669e3722fa.tar.bz2
rails-e4c9bd9828e107214d03a66679a89f669e3722fa.zip
Merge pull request #17980 from gsamokovarov/rescuable-case-operator
Add class level case operator support for error dispatching in Rescuable
Diffstat (limited to 'activesupport/test/rescuable_test.rb')
-rw-r--r--activesupport/test/rescuable_test.rb29
1 files changed, 27 insertions, 2 deletions
diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb
index b8af888f7c..bd43ad0797 100644
--- a/activesupport/test/rescuable_test.rb
+++ b/activesupport/test/rescuable_test.rb
@@ -12,6 +12,12 @@ end
class CoolError < StandardError
end
+module WeirdError
+ def self.===(other)
+ Exception === other && other.respond_to?(:weird?)
+ end
+end
+
class Stargate
attr_accessor :result
@@ -29,6 +35,10 @@ class Stargate
@result = e.message
end
+ rescue_from WeirdError do
+ @result = 'weird'
+ end
+
def dispatch(method)
send(method)
rescue Exception => e
@@ -47,6 +57,16 @@ class Stargate
raise MadRonon.new("dex")
end
+ def weird
+ StandardError.new.tap do |exc|
+ def exc.weird?
+ true
+ end
+
+ raise exc
+ end
+ end
+
def sos
@result = 'killed'
end
@@ -91,14 +111,19 @@ class RescuableTest < ActiveSupport::TestCase
assert_equal 'dex', @stargate.result
end
+ def test_rescue_from_error_dispatchers_with_case_operator
+ @stargate.dispatch :weird
+ assert_equal 'weird', @stargate.result
+ end
+
def test_rescues_defined_later_are_added_at_end_of_the_rescue_handlers_array
- expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon"]
+ expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "WeirdError"]
result = @stargate.send(:rescue_handlers).collect(&:first)
assert_equal expected, result
end
def test_children_should_inherit_rescue_definitions_from_parents_and_child_rescue_should_be_appended
- expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "CoolError"]
+ expected = ["WraithAttack", "WraithAttack", "NuclearExplosion", "MadRonon", "WeirdError", "CoolError"]
result = @cool_stargate.send(:rescue_handlers).collect(&:first)
assert_equal expected, result
end