From a213c2ed9c84f0f64f0664e820227034d078f9f9 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 9 May 2012 04:09:25 +0000 Subject: Imported minitest 3.0.0 (r7435) w/ fixes for rubygems. 10955 tests, 2253343 assertions, 1 failures, 1 errors, 28 skips minus drb tests on x86_64-darwin11.3.0 and reviewed by drbrain git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/minitest/test_minitest_mock.rb | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'test/minitest/test_minitest_mock.rb') 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 -- cgit v1.2.3