diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-05-11 16:31:06 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-05-12 17:24:43 +0900 |
commit | 3456335a9c624cd5f475fc71cc65e72d97acb86e (patch) | |
tree | 887026f8023f342bc5d4a573e6e6c2d22d5ea96d /lib/rubygems | |
parent | ff3f990499d041d39bc4ad2ca3244be8f6f1d552 (diff) |
[rubygems/rubygems] Removed minitest/mock from test/rubygems/test_gem_remote_fetcher.rb
https://github.com/rubygems/rubygems/commit/f1af59fe02
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4491
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/test_case.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 3d8e6f46cb..f8a262130a 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -1557,4 +1557,37 @@ Also, a list: end if Gem::HAVE_OPENSSL end +class Object + def stub name, val_or_callable, *block_args + new_name = "__minitest_stub__#{name}" + + metaclass = class << self; self; end + + if respond_to? name and not methods.map(&:to_s).include? name.to_s then + metaclass.send :define_method, name do |*args| + super(*args) + end + end + + metaclass.send :alias_method, new_name, name + + metaclass.send :define_method, name do |*args, &blk| + if val_or_callable.respond_to? :call then + val_or_callable.call(*args, &blk) + else + blk.call(*block_args) if blk + val_or_callable + end + end + + metaclass.send(:ruby2_keywords, name) if metaclass.respond_to?(:ruby2_keywords, true) + + yield self + ensure + metaclass.send :undef_method, name + metaclass.send :alias_method, name, new_name + metaclass.send :undef_method, new_name + end +end + require 'rubygems/test_utilities' |