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

ruby-changes:46153

From: nobu <ko1@a...>
Date: Fri, 7 Apr 2017 12:56:22 +0900 (JST)
Subject: [ruby-changes:46153] nobu:r58266 (trunk): assert_not_respond_to private method

nobu	2017-04-07 12:56:16 +0900 (Fri, 07 Apr 2017)

  New Revision: 58266

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

  Log:
    assert_not_respond_to private method
    
    * test/lib/test/unit/assertions.rb (assert_not_respond_to): allow
      private flag as well as assert_respond_to.

  Modified files:
    trunk/test/lib/test/unit/assertions.rb
Index: test/lib/test/unit/assertions.rb
===================================================================
--- test/lib/test/unit/assertions.rb	(revision 58265)
+++ test/lib/test/unit/assertions.rb	(revision 58266)
@@ -376,6 +376,29 @@ EOT https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L376
       end
 
       # :call-seq:
+      #   assert_not_respond_to( object, method, failure_message = nil )
+      #
+      #Tests if the given Object does not respond to +method+.
+      #
+      #An optional failure message may be provided as the final argument.
+      #
+      #    assert_not_respond_to("hello", :reverse)  #Fails
+      #    assert_not_respond_to("hello", :does_not_exist)  #Succeeds
+      def assert_not_respond_to(obj, (meth, *priv), msg = nil)
+        unless priv.empty?
+          msg = message(msg) {
+            "Expected #{mu_pp(obj)} (#{obj.class}) to not respond to ##{meth}#{" privately" if priv[0]}"
+          }
+          return assert obj.respond_to?(meth, *priv), msg
+        end
+        #get rid of overcounting
+        if caller_locations(1, 1)[0].path.start_with?(MINI_DIR)
+          return unless obj.respond_to?(meth)
+        end
+        refute_respond_to(obj, meth, msg)
+      end
+
+      # :call-seq:
       #   assert_send( +send_array+, failure_message = nil )
       #
       # Passes if the method send returns a true value.

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

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