From 5339f813be99012aba01586743d8b24f065e7034 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 13 Jan 2009 03:28:32 +0000 Subject: Change Object#try to raise NoMethodError on private methods and always return nil when Object is nil [Pratik Naik, Lawrence Pit] --- .../test/core_ext/object_and_class_ext_test.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'activesupport/test') diff --git a/activesupport/test/core_ext/object_and_class_ext_test.rb b/activesupport/test/core_ext/object_and_class_ext_test.rb index 2f79b6f67f..0bdbd14f33 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -256,21 +256,13 @@ class ObjectTryTest < Test::Unit::TestCase def test_nonexisting_method method = :undefined_method assert !@string.respond_to?(method) - assert_nil @string.try(method) + assert_raises(NoMethodError) { @string.try(method) } end def test_valid_method assert_equal 5, @string.try(:size) end - def test_valid_private_method - class << @string - private :size - end - - assert_equal 5, @string.try(:size) - end - def test_argument_forwarding assert_equal 'Hey', @string.try(:sub, 'llo', 'y') end @@ -278,4 +270,13 @@ class ObjectTryTest < Test::Unit::TestCase def test_block_forwarding assert_equal 'Hey', @string.try(:sub, 'llo') { |match| 'y' } end + + def test_nil_to_type + assert_nil nil.try(:to_s) + assert_nil nil.try(:to_i) + end + + def test_false_try + assert_equal 'false', false.try(:to_s) + end end -- cgit v1.2.3