aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/rescuable_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2008-10-04 21:48:18 +0100
committerPratik Naik <pratiknaik@gmail.com>2008-10-04 22:13:50 +0100
commit259a7a844b53b7d508145cc61fed9e11581e5409 (patch)
treeca91608fbab39d03b59137d018046606717883bd /activesupport/test/rescuable_test.rb
parent964dfc15572d7c10771c81ac3cbfb455dd5e378e (diff)
downloadrails-259a7a844b53b7d508145cc61fed9e11581e5409.tar.gz
rails-259a7a844b53b7d508145cc61fed9e11581e5409.tar.bz2
rails-259a7a844b53b7d508145cc61fed9e11581e5409.zip
Add tests for ActiveSupport::Rescuable. Use ActiveSupport::Rescuable in ActionController::Base.
Diffstat (limited to 'activesupport/test/rescuable_test.rb')
-rw-r--r--activesupport/test/rescuable_test.rb75
1 files changed, 75 insertions, 0 deletions
diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb
new file mode 100644
index 0000000000..9f2b783b2e
--- /dev/null
+++ b/activesupport/test/rescuable_test.rb
@@ -0,0 +1,75 @@
+require 'abstract_unit'
+
+class WraithAttack < StandardError
+end
+
+class NuclearExplosion < StandardError
+end
+
+class MadRonon < StandardError
+ attr_accessor :message
+
+ def initialize(message)
+ @message = message
+ super()
+ end
+end
+
+class Stargate
+ attr_accessor :result
+
+ include ActiveSupport::Rescuable
+
+ rescue_from WraithAttack, :with => :sos
+
+ rescue_from NuclearExplosion do
+ @result = 'alldead'
+ end
+
+ rescue_from MadRonon do |e|
+ @result = e.message
+ end
+
+ def dispatch(method)
+ send(method)
+ rescue Exception => e
+ rescue_with_handler(e)
+ end
+
+ def attack
+ raise WraithAttack
+ end
+
+ def nuke
+ raise NuclearExplosion
+ end
+
+ def ronanize
+ raise MadRonon.new("dex")
+ end
+
+ def sos
+ @result = 'killed'
+ end
+end
+
+class RescueableTest < Test::Unit::TestCase
+ def setup
+ @stargate = Stargate.new
+ end
+
+ def test_rescue_from_with_method
+ @stargate.dispatch :attack
+ assert_equal 'killed', @stargate.result
+ end
+
+ def test_rescue_from_with_block
+ @stargate.dispatch :nuke
+ assert_equal 'alldead', @stargate.result
+ end
+
+ def test_rescue_from_with_block_with_args
+ @stargate.dispatch :ronanize
+ assert_equal 'dex', @stargate.result
+ end
+end