Skip to content

Commit

Permalink
- Reverted stubbing of module methods change. Stub the user, not the …
Browse files Browse the repository at this point in the history
…impl. (ab9/tyabe)

[git-p4: depot-paths = "//src/minitest/dev/": change = 8437]
  • Loading branch information
zenspider committed Apr 21, 2013
1 parent 7e25922 commit 6b30ac8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/minitest/mock.rb
Expand Up @@ -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|
Expand Down
26 changes: 24 additions & 2 deletions test/minitest/test_minitest_mock.rb
Expand Up @@ -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
Expand Down

0 comments on commit 6b30ac8

Please sign in to comment.