diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2012-07-27 12:20:50 -0500 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2012-07-27 12:22:38 -0500 |
commit | 99ea1a875b06feb4346869f371e2a57a2cc0a0fc (patch) | |
tree | 1f05fdcff4afc50dc39537b50c595fc5acde059e /activesupport/test | |
parent | 3205c768b7c592e5b96fdf6a6dd0fd3c2c9e5775 (diff) | |
download | rails-99ea1a875b06feb4346869f371e2a57a2cc0a0fc.tar.gz rails-99ea1a875b06feb4346869f371e2a57a2cc0a0fc.tar.bz2 rails-99ea1a875b06feb4346869f371e2a57a2cc0a0fc.zip |
will now return nil instead of raise a NoMethodError if the receiving object does not implement the method
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 8 |
1 files changed, 4 insertions, 4 deletions
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 |