File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -1557,4 +1557,37 @@ def self.key_path(key_name)
1557
1557
end if Gem ::HAVE_OPENSSL
1558
1558
end
1559
1559
1560
+ class Object
1561
+ def stub name , val_or_callable , *block_args
1562
+ new_name = "__minitest_stub__#{ name } "
1563
+
1564
+ metaclass = class << self ; self ; end
1565
+
1566
+ if respond_to? name and not methods . map ( &:to_s ) . include? name . to_s then
1567
+ metaclass . send :define_method , name do |*args |
1568
+ super ( *args )
1569
+ end
1570
+ end
1571
+
1572
+ metaclass . send :alias_method , new_name , name
1573
+
1574
+ metaclass . send :define_method , name do |*args , &blk |
1575
+ if val_or_callable . respond_to? :call then
1576
+ val_or_callable . call ( *args , &blk )
1577
+ else
1578
+ blk . call ( *block_args ) if blk
1579
+ val_or_callable
1580
+ end
1581
+ end
1582
+
1583
+ metaclass . send ( :ruby2_keywords , name ) if metaclass . respond_to? ( :ruby2_keywords , true )
1584
+
1585
+ yield self
1586
+ ensure
1587
+ metaclass . send :undef_method , name
1588
+ metaclass . send :alias_method , name , new_name
1589
+ metaclass . send :undef_method , new_name
1590
+ end
1591
+ end
1592
+
1560
1593
require 'rubygems/test_utilities'
Original file line number Diff line number Diff line change 10
10
11
11
require 'rubygems/remote_fetcher'
12
12
require 'rubygems/package'
13
- require 'minitest/mock'
14
13
15
14
# = Testing Proxy Settings
16
15
#
You can’t perform that action at this time.
0 commit comments