aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/object_and_class_ext_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2012-07-27 12:33:02 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2012-07-27 12:33:02 -0500
commit04998cd0c92a13332844d04145a4ede3184c7bd0 (patch)
tree9c2a0727cea530dcfb49a098b56a4c2216c2c86e /activesupport/test/core_ext/object_and_class_ext_test.rb
parent99ea1a875b06feb4346869f371e2a57a2cc0a0fc (diff)
downloadrails-04998cd0c92a13332844d04145a4ede3184c7bd0.tar.gz
rails-04998cd0c92a13332844d04145a4ede3184c7bd0.tar.bz2
rails-04998cd0c92a13332844d04145a4ede3184c7bd0.zip
Add Object#try! with the old NoMethodError raising behavior
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.rb26
1 files changed, 25 insertions, 1 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 5dd965f405..ec7dd6d4fb 100644
--- a/activesupport/test/core_ext/object_and_class_ext_test.rb
+++ b/activesupport/test/core_ext/object_and_class_ext_test.rb
@@ -108,6 +108,18 @@ class ObjectTryTest < ActiveSupport::TestCase
assert_nil @string.try(method, 'llo', 'y')
end
+ def test_nonexisting_method_bang
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_raise(NoMethodError) { @string.try!(method) }
+ end
+
+ def test_nonexisting_method_with_arguments_bang
+ method = :undefined_method
+ assert !@string.respond_to?(method)
+ assert_raise(NoMethodError) { @string.try!(method, 'llo', 'y') }
+ end
+
def test_valid_method
assert_equal 5, @string.try(:size)
end
@@ -124,7 +136,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
@@ -139,6 +151,18 @@ class ObjectTryTest < ActiveSupport::TestCase
assert_equal false, ran
end
+ def test_try_with_private_method_bang
+ klass = Class.new do
+ private
+
+ def private_method
+ 'private method'
+ end
+ end
+
+ assert_raise(NoMethodError) { klass.new.try!(:private_method) }
+ end
+
def test_try_with_private_method
klass = Class.new do
private