test/mocha/mock_methods_test.rb in mocha-0.3.3 vs test/mocha/mock_methods_test.rb in mocha-0.4.0
- old
+ new
@@ -47,13 +47,23 @@
mock.extend(MockMethods)
expectation1 = mock.expects(:my_method).with(:argument1, :argument2)
expectation2 = mock.expects(:my_method).with(:argument3, :argument4)
- assert_equal expectation2, mock.matching_expectation(:my_method, :argument3, :argument4)
+ assert_same expectation2, mock.matching_expectation(:my_method, :argument3, :argument4)
end
+ def test_should_find_most_recent_matching_expectation
+ mock = Object.new
+ mock.extend(MockMethods)
+
+ expectation1 = mock.expects(:my_method).with(:argument1, :argument2)
+ expectation2 = mock.expects(:my_method).with(:argument1, :argument2)
+
+ assert_same expectation2, mock.matching_expectation(:my_method, :argument1, :argument2)
+ end
+
def test_should_invoke_expectation_and_return_result
mock = Object.new
mock.extend(MockMethods)
mock.expects(:my_method).returns(:result)
@@ -65,11 +75,11 @@
def test_should_not_raise_error_if_stubbing_everything
mock = Class.new { def initialize; @stub_everything = true; end }.new
mock.extend(MockMethods)
result = nil
- assert_nothing_raised(Test::Unit::AssertionFailedError) do
+ assert_nothing_raised(ExpectationError) do
result = mock.unexpected_method
end
assert_nil result
end
@@ -82,11 +92,11 @@
end
def test_should_raise_assertion_error_for_unexpected_method_call
mock = Object.new
mock.extend(MockMethods)
- error = assert_raise(Test::Unit::AssertionFailedError) do
+ error = assert_raise(ExpectationError) do
mock.unexpected_method_called(:my_method, :argument1, :argument2)
end
assert_match /my_method/, error.message
assert_match /argument1/, error.message
assert_match /argument2/, error.message
@@ -127,20 +137,20 @@
mock = Object.new
mock.extend(MockMethods)
mock.expects(:method1)
mock.expects(:method2)
mock.method1
- assert_raise(Test::Unit::AssertionFailedError) do
+ assert_raise(ExpectationError) do
mock.verify
end
end
def test_should_report_possible_expectations
mock = Object.new.extend(MockMethods)
- mock.expects(:meth).with(1)
- exception = assert_raise(Test::Unit::AssertionFailedError) { mock.meth(2) }
- assert_equal "Unexpected message :meth(2) sent to #{mock.mocha_inspect}\nSimilar expectations :meth(1)", exception.message
+ 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:\nexpected_method(1)", exception.message
end
def test_should_pass_block_through_to_expectations_verify_method
mock = Object.new
mock.extend(MockMethods)
@@ -172,6 +182,54 @@
mock = Object.new
mock.extend(MockMethods)
assert_equal false, mock.respond_to?(:method1)
end
+ def test_should_set_up_multiple_expectations_with_return_values
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.expects(:method1 => :result1, :method2 => :result2)
+ assert_equal :result1, mock.method1
+ assert_equal :result2, mock.method2
+ end
+
+ def test_should_set_up_multiple_stubs_with_return_values
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.stubs(:method1 => :result1, :method2 => :result2)
+ assert_equal :result1, mock.method1
+ assert_equal :result2, mock.method2
+ end
+
+ def test_should_match_most_recent_call_to_expects
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.expects(:method1).returns(0)
+ mock.expects(:method1).returns(1)
+ assert_equal 1, mock.method1
+ end
+
+ def test_should_match_most_recent_call_to_stubs
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.stubs(:method1).returns(0)
+ mock.stubs(:method1).returns(1)
+ assert_equal 1, mock.method1
+ end
+
+ def test_should_match_call_to_expects_with_previous_call_to_stubs
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.stubs(:method1).returns(0)
+ mock.expects(:method1).returns(1)
+ assert_equal 1, mock.method1
+ end
+
+ def test_should_match_call_to_stubs_with_previous_call_to_expects
+ mock = Object.new
+ mock.extend(MockMethods)
+ mock.expects(:method1).returns(0)
+ mock.stubs(:method1).returns(1)
+ assert_equal 1, mock.method1
+ end
+
end
\ No newline at end of file