From 84833bd60a00a5f1078b3c3b54f0d0b1e44e0dea Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 Apr 2017 03:56:16 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/lib/test/unit/assertions.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index c98e1ade58..ae8327f89a 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -375,6 +375,29 @@ EOT super(obj, meth, msg) 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 ) # -- cgit v1.2.3