File tree Expand file tree Collapse file tree 1 file changed +30
-1
lines changed
Expand file tree Collapse file tree 1 file changed +30
-1
lines changed Original file line number Diff line number Diff line change 33require 'resolv'
44require 'socket'
55require 'tempfile'
6- require 'minitest/mock'
6+
7+ class Object # :nodoc:
8+ def stub name , val_or_callable , &block
9+ new_name = "__minitest_stub__#{ name } "
10+
11+ metaclass = class << self ; self ; end
12+
13+ if respond_to? name and not methods . map ( &:to_s ) . include? name . to_s then
14+ metaclass . send :define_method , name do |*args |
15+ super ( *args )
16+ end
17+ end
18+
19+ metaclass . send :alias_method , new_name , name
20+
21+ metaclass . send :define_method , name do |*args |
22+ if val_or_callable . respond_to? :call then
23+ val_or_callable . call ( *args )
24+ else
25+ val_or_callable
26+ end
27+ end
28+
29+ yield self
30+ ensure
31+ metaclass . send :undef_method , name
32+ metaclass . send :alias_method , name , new_name
33+ metaclass . send :undef_method , new_name
34+ end unless method_defined? ( :stub ) # lib/rubygems/test_case.rb also has the same method definition
35+ end
736
837class TestResolvDNS < Test ::Unit ::TestCase
938 def setup
You can’t perform that action at this time.
0 commit comments