test/unit/mock_test.rb in mocha-0.5.6 vs test/unit/mock_test.rb in mocha-0.9.0

- old
+ new

@@ -1,9 +1,10 @@ require File.join(File.dirname(__FILE__), "..", "test_helper") require 'mocha/mock' require 'mocha/expectation_error' require 'set' +require 'simple_counter' class MockTest < Test::Unit::TestCase include Mocha @@ -31,30 +32,10 @@ mock = Mock.new mock.stub_everything assert_equal true, mock.everything_stubbed end - def test_should_display_object_id_for_mocha_inspect_if_mock_has_no_name - mock = Mock.new - assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.mocha_inspect - end - - def test_should_display_name_for_mocha_inspect_if_mock_has_name - mock = Mock.new('named_mock') - assert_equal "#<Mock:named_mock>", mock.mocha_inspect - end - - def test_should_display_object_id_for_inspect_if_mock_has_no_name - mock = Mock.new - assert_match Regexp.new("^#<Mock:0x[0-9A-Fa-f]{1,12}>$"), mock.inspect - end - - def test_should_display_name_for_inspect_if_mock_has_name - mock = Mock.new('named_mock') - assert_equal "#<Mock:named_mock>", mock.inspect - end - def test_should_be_able_to_extend_mock_object_with_module mock = Mock.new assert_nothing_raised(ExpectationError) { mock.extend(Module.new) } end @@ -71,11 +52,11 @@ def test_should_be_able_to_mock_standard_object_methods mock = Mock.new OBJECT_METHODS.each { |method| mock.__expects__(method.to_sym).returns(method) } OBJECT_METHODS.each { |method| assert_equal method, mock.__send__(method.to_sym) } - assert_nothing_raised(ExpectationError) { mock.verify } + assert mock.verified? end def test_should_be_able_to_stub_standard_object_methods mock = Mock.new OBJECT_METHODS.each { |method| mock.__stubs__(method.to_sym).returns(method) } @@ -148,33 +129,31 @@ mock.my_method(:argument1, :argument2) assert_equal :my_method, mock.symbol assert_equal [:argument1, :argument2], mock.arguments end - def test_should_verify_that_all_expectations_have_been_fulfilled + def test_should_not_verify_successfully_because_not_all_expectations_have_been_satisfied mock = Mock.new mock.expects(:method1) mock.expects(:method2) mock.method1 - assert_raise(ExpectationError) do - mock.verify - end + assert !mock.verified? end - def test_should_report_possible_expectations + def test_should_increment_assertion_counter_for_every_verified_expectation mock = Mock.new - mock.expects(:expected_method).with(1) - exception = assert_raise(ExpectationError) { mock.expected_method(2) } - assert_equal "#{mock.mocha_inspect}.expected_method(2) - expected calls: 0, actual calls: 1\nSimilar expectations:\n#{mock.mocha_inspect}.expected_method(1)", exception.message - end - - def test_should_pass_block_through_to_expectations_verify_method - mock = Mock.new - expected_expectation = mock.expects(:method1) + + mock.expects(:method1) mock.method1 - expectations = [] - mock.verify() { |expectation| expectations << expectation } - assert_equal [expected_expectation], expectations + + mock.expects(:method2) + mock.method2 + + assertion_counter = SimpleCounter.new + + mock.verified?(assertion_counter) + + assert_equal 2, assertion_counter.count end def test_should_yield_supplied_parameters_to_block mock = Mock.new parameters_for_yield = [1, 2, 3] \ No newline at end of file