Skip to content

Commit db70f32

Browse files
committed
Removed minitest/mock
1 parent 095f1c0 commit db70f32

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

test/resolv/test_dns.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33
require 'resolv'
44
require 'socket'
55
require '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

837
class TestResolvDNS < Test::Unit::TestCase
938
def setup

0 commit comments

Comments
 (0)