diff options
author | Ryan Bigg <radarlistener@gmail.com> | 2008-10-06 11:57:12 +1030 |
---|---|---|
committer | Ryan Bigg <radarlistener@gmail.com> | 2008-10-06 11:57:12 +1030 |
commit | a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7 (patch) | |
tree | bb0b0e9423d4e259de6041e661bba119f7871faa /activesupport/test | |
parent | b340337aaff5b59fdf2110207fec3e1c43f1380a (diff) | |
parent | 6090513cfb8acb5554a6653a6f2cb87648585d41 (diff) | |
download | rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.tar.gz rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.tar.bz2 rails-a21d8f632fe8aa3bf4c1b83accc7a2dd230c28e7.zip |
Merge branch 'master' of git@github.com:lifo/docrails
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/rescuable_test.rb | 75 | ||||
-rw-r--r-- | activesupport/test/secure_random_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/test_test.rb | 18 |
3 files changed, 97 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 diff --git a/activesupport/test/secure_random_test.rb b/activesupport/test/secure_random_test.rb index b0b6c21a81..44694cd811 100644 --- a/activesupport/test/secure_random_test.rb +++ b/activesupport/test/secure_random_test.rb @@ -12,4 +12,8 @@ class SecureRandomTest < Test::Unit::TestCase b2 = ActiveSupport::SecureRandom.hex(64) assert_not_equal b1, b2 end + + def test_random_number + assert ActiveSupport::SecureRandom.random_number(5000) < 5000 + end end diff --git a/activesupport/test/test_test.rb b/activesupport/test/test_test.rb index 26a45af255..4e253848f6 100644 --- a/activesupport/test/test_test.rb +++ b/activesupport/test/test_test.rb @@ -60,6 +60,24 @@ class AssertDifferenceTest < Test::Unit::TestCase @object.increment end end + + def test_array_of_expressions_identify_failure + assert_difference ['@object.num', '1 + 1'] do + @object.increment + end + fail 'should not get to here' + rescue Test::Unit::AssertionFailedError => e + assert_equal "<1 + 1> was the expression that failed.\n<3> expected but was\n<2>.", e.message + end + + def test_array_of_expressions_identify_failure_when_message_provided + assert_difference ['@object.num', '1 + 1'], 1, 'something went wrong' do + @object.increment + end + fail 'should not get to here' + rescue Test::Unit::AssertionFailedError => e + assert_equal "something went wrong.\n<1 + 1> was the expression that failed.\n<3> expected but was\n<2>.", e.message + end else def default_test; end end |