diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-26 10:55:46 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-26 10:55:46 +0000 |
commit | f79d891aad37ee9b267f431f74ca1e527c396794 (patch) | |
tree | 566978473e90ed13d90efce3812c175e9e0b1c4f /test/ruby/test_exception.rb | |
parent | 97d9be7908ee76b5af3b6d25ee788a32ebd4ef3d (diff) | |
download | ruby-f79d891aad37ee9b267f431f74ca1e527c396794.tar.gz |
test_exception.rb: NameError.new NoMethodError.new
* test/ruby/test_exception.rb: added tests for NameError.new, and
NoMethodError.new including priv argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62056 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_exception.rb')
-rw-r--r-- | test/ruby/test_exception.rb | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 98462bef93..4fcd905685 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -842,6 +842,67 @@ end.join alias inspect pretty_inspect end + def test_name_error_new_default + error = NameError.new + assert_equal("NameError", error.message) + end + + def test_name_error_new_message + error = NameError.new("Message") + assert_equal("Message", error.message) + end + + def test_name_error_new_name + error = NameError.new("Message") + assert_nil(error.name) + + error = NameError.new("Message", :foo) + assert_equal(:foo, error.name) + end + + def test_name_error_new_receiver + receiver = Object.new + + error = NameError.new + assert_raise(ArgumentError) {error.receiver} + assert_equal("NameError", error.message) + end + + def test_nomethod_error_new_default + error = NoMethodError.new + assert_equal("NoMethodError", error.message) + end + + def test_nomethod_error_new_message + error = NoMethodError.new("Message") + assert_equal("Message", error.message) + end + + def test_nomethod_error_new_name + error = NoMethodError.new("Message") + assert_nil(error.name) + + error = NoMethodError.new("Message", :foo) + assert_equal(:foo, error.name) + end + + def test_nomethod_error_new_name_args + error = NoMethodError.new("Message", :foo) + assert_nil(error.args) + + error = NoMethodError.new("Message", :foo, [1, 2]) + assert_equal([:foo, [1, 2]], [error.name, error.args]) + end + + def test_nomethod_error_new_name_args_priv + error = NoMethodError.new("Message", :foo, [1, 2]) + assert_not_predicate(error, :private_call?) + + error = NoMethodError.new("Message", :foo, [1, 2], true) + assert_equal([:foo, [1, 2], true], + [error.name, error.args, error.private_call?]) + end + def test_name_error_info_const obj = PrettyObject.new |