1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#!/usr/bin/env ruby
#---
# Copyright 2003-2013 by Jim Weirich (jim.weirich@gmail.com).
# All rights reserved.
# Permission is granted for use, copying, modification, distribution,
# and distribution of modified versions of this work as long as the
# above copyright notice is included.
#+++
require 'test_helper'
# The following tests exercise Test::Unit integration. They are
# disabled if actually running under MiniTest because the MiniTest is
# different enough internally that the tests are not worthwhile.
unless defined?(MiniTest)
class TestTuIntegrationFlexMockMethod < Test::Unit::TestCase
include FlexMock::Minitest
def test_can_construct_flexmock
mock = flexmock("x")
mock.should_receive(:hi).and_return(:hello)
assert_equal :hello, mock.hi
end
def test_can_construct_flexmock_with_block
mock = flexmock("x") do |m|
m.should_receive(:hi).and_return(:hello)
end
assert_equal :hello, mock.hi
end
end
class TestTuIntegrationMockVerificationInTeardown < Test::Unit::TestCase
include FlexMock::Minitest
def teardown
assert_raise(assertion_failed_error) do
super
end
end
def test_mock_verification_occurs_during_teardown
flexmock("xyz").should_receive(:hi).with(any).once
end
end
class TestTuIntegrationMockVerificationWithoutSetup < Test::Unit::TestCase
include FlexMock::Minitest
def teardown
assert_raise(assertion_failed_error) do
super
end
end
def test_mock_verification_occurs_during_teardown
flexmock("xyz").should_receive(:hi).with(any).once
end
end
class TestTuIntegrationMockVerificationForgetfulSetup < Test::Unit::TestCase
include FlexMock::Minitest
def teardown
assert_raise(assertion_failed_error) do
super
end
end
def test_mock_verification_occurs_during_teardown
flexmock("xyz").should_receive(:hi).with(any).once
end
end
class TestTuIntegrationSetupOverridenAndNoMocksOk < Test::Unit::TestCase
include FlexMock::Minitest
def test_mock_verification_occurs_during_teardown
end
end
class TestTuIntegrationFailurePreventsVerification < Test::Unit::TestCase
include FlexMock::Minitest
def test_mock_verification_occurs_during_teardown
flexmock('m').should_receive(:hi).once
simulate_failure
end
private
def simulate_failure
@test_passed = false
end
end
end
|