diff options
Diffstat (limited to 'activesupport/test/core_ext/object_and_class_ext_test.rb')
-rw-r--r-- | activesupport/test/core_ext/object_and_class_ext_test.rb | 25 |
1 files changed, 25 insertions, 0 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 e88dcb52d5..fbdce56ac2 100644 --- a/activesupport/test/core_ext/object_and_class_ext_test.rb +++ b/activesupport/test/core_ext/object_and_class_ext_test.rb @@ -247,3 +247,28 @@ class ObjectInstanceVariableTest < Test::Unit::TestCase [arg] + instance_exec('bar') { |v| [reverse, v] } } end end + +class ObjectTryTest < Test::Unit::TestCase + def setup + @string = "Hello" + end + + def test_nonexisting_method + method = :undefined_method + assert !@string.respond_to?(method) + assert_nil @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 + +end |