Skip to content
Browse files

Fixed a mistake in the docs and a mistake in the tests from tinogomes…

… commit. Also tidied things up a bit e.g. it's enough to document and test 3 invocations, 2 invocations & 1 invocation - no need for 0 invocations.
  • Loading branch information...
1 parent b056bc5 commit 6e04385e1b49f230edf364d497f1717034f74469 @floehopper floehopper committed
Showing with 22 additions and 32 deletions.
  1. +17 −22 lib/mocha/expectation.rb
  2. +3 −3 test/acceptance/expected_invocation_count_test.rb
  3. +2 −7 test/unit/expectation_test.rb
View
39 lib/mocha/expectation.rb
@@ -43,56 +43,51 @@ def times(range)
self
end
- # :call-seq: once() -> expectation
+ # :call-seq: twice() -> expectation
#
- # Modifies expectation so that the expected method must be called exactly once.
- # Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
+ # Modifies expectation so that the expected method must be called exactly twice.
# object = mock()
- # object.expects(:expected_method).once
+ # object.expects(:expected_method).twice
+ # object.expected_method
# object.expected_method
# # => verify succeeds
#
# object = mock()
- # object.expects(:expected_method).once
+ # object.expects(:expected_method).twice
+ # object.expected_method
# object.expected_method
# object.expected_method
# # => verify fails
#
# object = mock()
- # object.expects(:expected_method).once
+ # object.expects(:expected_method).twice
+ # object.expected_method
# # => verify fails
- def once
- @cardinality = Cardinality.exactly(1)
+ def twice
+ @cardinality = Cardinality.exactly(2)
self
end
- # :call-seq: twice() -> expectation
+ # :call-seq: once() -> expectation
#
- # Modifies expectation so that the expected method must be called exactly twice.
+ # Modifies expectation so that the expected method must be called exactly once.
# Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
# object = mock()
- # object.expects(:expected_method).twice
- # object.expected_method
+ # object.expects(:expected_method).once
# object.expected_method
# # => verify succeeds
#
# object = mock()
- # object.expects(:expected_method).twice
- # object.expected_method
+ # object.expects(:expected_method).once
# object.expected_method
# object.expected_method
- # # => verify succeeds
- #
- # object = mock()
- # object.expects(:expected_method).twice
- # object.expected_method
# # => verify fails
#
# object = mock()
- # object.expects(:expected_method).twice
+ # object.expects(:expected_method).once
# # => verify fails
- def twice
- @cardinality = Cardinality.exactly(2)
+ def once
+ @cardinality = Cardinality.exactly(1)
self
end
View
6 test/acceptance/expected_invocation_count_test.rb
@@ -35,7 +35,7 @@ def test_should_fail_fast_if_method_is_never_expected_but_is_called_once
def test_should_pass_if_method_is_expected_twice_and_is_called_twice
test_result = run_test do
mock = mock('mock')
- mock.expects(:method).times(2)
+ mock.expects(:method).twice
2.times { mock.method }
end
assert_passed(test_result)
@@ -44,7 +44,7 @@ def test_should_pass_if_method_is_expected_twice_and_is_called_twice
def test_should_fail_if_method_is_expected_twice_but_is_called_once
test_result = run_test do
mock = mock('mock')
- mock.expects(:method).times(2)
+ mock.expects(:method).twice
1.times { mock.method }
end
assert_failed(test_result)
@@ -54,7 +54,7 @@ def test_should_fail_if_method_is_expected_twice_but_is_called_once
def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times
test_result = run_test do
mock = mock('mock')
- mock.expects(:method).times(2)
+ mock.expects(:method).twice
3.times { mock.method }
end
assert_failed(test_result)
View
9 test/unit/expectation_test.rb
@@ -253,8 +253,8 @@ def test_should_verify_successfully_if_call_expected_once_and_invoked_once
assert expectation.verified?
end
- def test_should_verify_successfully_if_call_expected_twice_and_invoked_three_times
- expectation = new_expectation.once
+ def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
+ expectation = new_expectation.twice
expectation.invoke
expectation.invoke
expectation.invoke
@@ -267,11 +267,6 @@ def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
assert !expectation.verified?
end
- def test_should_not_verify_successfully_if_call_expected_twice_but_not_invoked
- expectation = new_expectation.twice
- assert !expectation.verified?
- end
-
def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
expectation = new_expectation.twice
expectation.invoke

0 comments on commit 6e04385

Please sign in to comment.
Something went wrong with that request. Please try again.