diff options
Diffstat (limited to 'test/minitest/test_minitest_mock.rb')
-rw-r--r-- | test/minitest/test_minitest_mock.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/minitest/test_minitest_mock.rb b/test/minitest/test_minitest_mock.rb index 02321e0f97..dcb140851a 100644 --- a/test/minitest/test_minitest_mock.rb +++ b/test/minitest/test_minitest_mock.rb @@ -210,3 +210,62 @@ class TestMiniTestMock < MiniTest::Unit::TestCase assert_equal exp, e.message end end + +require "test/minitest/metametameta" + +class TestMiniTestStub < MiniTest::Unit::TestCase + def setup + super + MiniTest::Unit::TestCase.reset + + @tc = MiniTest::Unit::TestCase.new 'fake tc' + @assertion_count = 1 + end + + def teardown + super + assert_equal @assertion_count, @tc._assertions + end + + def assert_stub val_or_callable + @assertion_count += 1 + + t = Time.now.to_i + + Time.stub :now, val_or_callable do + @tc.assert_equal 42, Time.now + end + + @tc.assert_operator Time.now.to_i, :>=, t + end + + def test_stub_value + assert_stub 42 + end + + def test_stub_block + assert_stub lambda { 42 } + end + + def test_stub_block_args + @assertion_count += 1 + + t = Time.now.to_i + + Time.stub :now, lambda { |n| n * 2 } do + @tc.assert_equal 42, Time.now(21) + end + + @tc.assert_operator Time.now.to_i, :>=, t + end + + def test_stub_callable + obj = Object.new + + def obj.call + 42 + end + + assert_stub obj + end +end |