New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't stub singleton methods of modules with 4.7.2 #272
Comments
On Apr 18, 2013, at 18:44 , Aaron Beckerman notifications@github.com wrote:
Grrr.... No. That was supposed to fix the stubbing of things like Kernel.sleep... I'm never gonna win. :( I'm knee deep in a minitest revamp and can't get my head out of this for a bit... Can you take a whack at it? I dunno if there is ever gonna be a single way to cover all cases and that's ok. |
As I understand it, the user wants to test code like this: class SlowClapper
def slow_clap
sleep 3
:clap
end
end But he doesn't want the sleep to happen during the tests. Is that the motivation? Here's how I would do it: class SlowClapperTest < MiniTest::Unit::TestCase
def test_slow_clap
slow_clapper = SlowClapper.new
slow_clapper.stub :sleep, nil do |fast_clapper|
assert_equal :clap, fast_clapper.slow_clap
end
end
end In other words, I would stub (the singleton class of) the object that actually receives the "sleep" message -- So, as far as this example is concerned, I don't see a need for 8bc0037. But am I misunderstanding the use case, or is there another use case you're trying to support? |
The following example broken: gem 'minitest' # '4.7.2'
require 'minitest/mock'
require 'minitest/autorun'
module Foo
def self.say
"Hello"
end
end
class TestSample < MiniTest::Unit::TestCase
def test_say
Foo.stub(:say, 'STUBBED!') do
assert_equal 'STUBBED!', Foo.say
end
end
end errors:
|
Fixed. Thanks guys. Sorry. |
With MiniTest 4.7.2:
Whereas with MiniTest 4.7.1:
Is this considered an acceptable side effect of 8bc0037?
The text was updated successfully, but these errors were encountered: