Skip to content
Browse files

- Reverted stubbing of module methods change. Stub the user, not the …

…impl. (ab9/tyabe)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8437]
  • Loading branch information...
1 parent 7e25922 commit 6b30ac8fd577d7aa601897ce24fd14369884b5cb @zenspider zenspider committed
Showing with 25 additions and 3 deletions.
  1. +1 −1 lib/minitest/mock.rb
  2. +24 −2 test/minitest/test_minitest_mock.rb
View
2 lib/minitest/mock.rb
@@ -166,7 +166,7 @@ class Object # :nodoc:
def stub name, val_or_callable, &block
new_name = "__minitest_stub__#{name}"
- metaclass = self.class == Module ? self : class << self; self; end
+ 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|
View
26 test/minitest/test_minitest_mock.rb
@@ -300,18 +300,40 @@ def assert_stub val_or_callable
end
end
- def test_stub_module
+ def test_stub_private_module_method
@assertion_count += 1
t0 = Time.now
- Kernel.stub :sleep, nil do
+ self.stub :sleep, nil do
@tc.assert_nil sleep(10)
end
@tc.assert_operator Time.now - t0, :<=, 1
end
+ def test_stub_private_module_method_indirect
+ @assertion_count += 1
+
+ slow_clapper = Class.new do
+ def slow_clap
+ sleep 3
+ :clap
+ end
+ end.new
+
+ slow_clapper.stub :sleep, nil do |fast_clapper|
+ @tc.assert_equal :clap, fast_clapper.slow_clap # either form works
+ @tc.assert_equal :clap, slow_clapper.slow_clap # yay closures
+ end
+ end
+
+ def test_stub_public_module_method
+ Math.stub(:log10, 42.0) do
+ @tc.assert_in_delta 42.0, Math.log10(1000)
+ end
+ end
+
def test_stub_value
assert_stub 42
end

0 comments on commit 6b30ac8

Please sign in to comment.
Something went wrong with that request. Please try again.