diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-07 03:56:16 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-04-07 03:56:16 +0000 |
commit | 495b2a246faf5d3dbf1cb5c1ea65823df5a8a5e3 (patch) | |
tree | 113d5e5a5eac14acbc523805cf2b6151c2af92c8 /test/lib | |
parent | 95b5e6d96c39bfd11a10a09a0f22850a01c739a7 (diff) | |
download | ruby-495b2a246faf5d3dbf1cb5c1ea65823df5a8a5e3.tar.gz |
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
Diffstat (limited to 'test/lib')
-rw-r--r-- | test/lib/test/unit/assertions.rb | 23 |
1 files changed, 23 insertions, 0 deletions
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 @@ -376,6 +376,29 @@ EOT 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. |