[前][次][番号順一覧][スレッド一覧]

ruby-changes:49938

From: nobu <ko1@a...>
Date: Fri, 26 Jan 2018 19:55:54 +0900 (JST)
Subject: [ruby-changes:49938] nobu:r62056 (trunk): test_exception.rb: NameError.new NoMethodError.new

nobu	2018-01-26 19:55:46 +0900 (Fri, 26 Jan 2018)

  New Revision: 62056

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62056

  Log:
    test_exception.rb: NameError.new NoMethodError.new
    
    * test/ruby/test_exception.rb: added tests for NameError.new, and
      NoMethodError.new including priv argument.

  Modified files:
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 62055)
+++ test/ruby/test_exception.rb	(revision 62056)
@@ -842,6 +842,67 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L842
       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
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]