From 99ea1a875b06feb4346869f371e2a57a2cc0a0fc Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 27 Jul 2012 12:20:50 -0500 Subject: will now return nil instead of raise a NoMethodError if the receiving object does not implement the method --- activesupport/test/core_ext/object_and_class_ext_test.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 98ab82609e..5dd965f405 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -99,13 +99,13 @@ class ObjectTryTest < ActiveSupport::TestCase def test_nonexisting_method method = :undefined_method assert !@string.respond_to?(method) - assert_raise(NoMethodError) { @string.try(method) } + assert_nil @string.try(method) end def test_nonexisting_method_with_arguments method = :undefined_method assert !@string.respond_to?(method) - assert_raise(NoMethodError) { @string.try(method, 'llo', 'y') } + assert_nil @string.try(method, 'llo', 'y') end def test_valid_method @@ -124,7 +124,7 @@ class ObjectTryTest < ActiveSupport::TestCase 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 @@ -148,6 +148,6 @@ class ObjectTryTest < ActiveSupport::TestCase end end - assert_raise(NoMethodError) { klass.new.try(:private_method) } + assert_nil klass.new.try(:private_method) end end -- cgit v1.2.3