Permalink
Browse files

- Fixed stubbing of module methods (eg Kernel#sleep). (steveklabnik)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8417]
  • Loading branch information...
1 parent fb93a40 commit 8bc003750a5013a040a17916a4d73dd95e4c2b3d @zenspider zenspider committed Apr 17, 2013
Showing with 13 additions and 1 deletion.
  1. +1 −1 lib/minitest/mock.rb
  2. +12 −0 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 = class << self; self; end
+ metaclass = self.class == Module ? self : 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
12 test/minitest/test_minitest_mock.rb
@@ -300,6 +300,18 @@ def assert_stub val_or_callable
end
end
+ def test_stub_module
+ @assertion_count += 1
+
+ t0 = Time.now
+
+ Kernel.stub :sleep, nil do
+ @tc.assert_nil sleep(10)
+ end
+
+ @tc.assert_operator Time.now - t0, :<=, 1
+ end
+
def test_stub_value
assert_stub 42
end

0 comments on commit 8bc0037

Please sign in to comment.