Skip to content

Commit

Permalink
use consistent phrasing for configured & invoked times
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr committed Oct 30, 2019
1 parent d8c2312 commit 4dea01a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/mocha/cardinality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def anticipated_times
if allowed_any_number_of_times?
'allowed any number of times'
elsif required.zero? && maximum.zero?
'expected never'
"expected #{times(maximum)}"
elsif required == maximum
"expected exactly #{times(required)}"
elsif infinite?(maximum)
Expand All @@ -74,7 +74,7 @@ def anticipated_times
end

def invoked_times
@invocations.none? ? 'not yet invoked' : "invoked #{times(@invocations.size)}"
"invoked #{times(@invocations.size)}"
end

def actual_invocations
Expand All @@ -87,6 +87,7 @@ def actual_invocations

def times(number)
case number
when 0 then 'never'
when 1 then 'once'
when 2 then 'twice'
else "#{number} times"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def assert_invocations(test_result, *invocations)
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<Mock:foo>.bar(1)',
'- expected exactly once, invoked never: #<Mock:foo>.bar(1)',
'satisfied expectations:',
*invocations
], test_result.failure_message_lines
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/exception_rescue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_unsatisfied_expectation_exception_is_not_caught_by_standard_rescue
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<Mock:mock>.some_method(any_parameters)'
'- expected exactly once, invoked never: #<Mock:mock>.some_method(any_parameters)'
], test_result.failure_message_lines
end
end
4 changes: 2 additions & 2 deletions test/acceptance/expected_invocation_count_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)'
'- expected at least once, invoked never: #<Mock:mock>.method(any_parameters)'
], test_result.failure_message_lines
end

Expand Down Expand Up @@ -224,7 +224,7 @@ def test_should_fail_fast_if_there_is_no_matching_expectation
assert_equal [
'unexpected invocation: #<Mock:mock>.method()',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<Mock:mock>.method(1)'
'- expected exactly once, invoked never: #<Mock:mock>.method(1)'
], test_result.failure_message_lines
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def my_instance_method; end
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<AnyInstance:superklass>.my_instance_method(any_parameters)'
'- expected exactly once, invoked never: #<AnyInstance:superklass>.my_instance_method(any_parameters)'
], test_result.failure_message_lines
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def self.my_class_method; end
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: superklass.my_class_method(any_parameters)'
'- expected exactly once, invoked never: superklass.my_class_method(any_parameters)'
], test_result.failure_message_lines
end
# rubocop:enable Lint/DuplicateMethods
Expand Down
6 changes: 3 additions & 3 deletions test/integration/shared_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_mock_object_unsatisfied_expectation
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
'- expected exactly once, invoked never: #<Mock:expecting invocation>.expected(any_parameters)'
], test_result.failure_message_lines
end

Expand Down Expand Up @@ -101,7 +101,7 @@ def test_mock_object_unsatisfied_expectation_in_setup
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
'- expected exactly once, not yet invoked: #<Mock:expecting invocation>.expected(any_parameters)'
'- expected exactly once, invoked never: #<Mock:expecting invocation>.expected(any_parameters)'
], test_result.failure_message_lines
end

Expand Down Expand Up @@ -151,7 +151,7 @@ def test_real_object_unsatisfied_expectation
assert_equal [
'not all expectations were satisfied',
'unsatisfied expectations:',
"- expected exactly once, not yet invoked: #{object.mocha_inspect}.expected(any_parameters)"
"- expected exactly once, invoked never: #{object.mocha_inspect}.expected(any_parameters)"
], test_result.failure_message_lines
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/expectation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def test_should_verify_successfully_if_expected_call_was_made_at_least_once
def test_should_not_verify_successfully_if_expected_call_was_not_made_at_least_once
expectation = new_expectation.with(1, 2, 3).at_least_once
assert !expectation.verified?
assert_match(/expected at least once, not yet invoked/i, expectation.mocha_inspect)
assert_match(/expected at least once, invoked never/i, expectation.mocha_inspect)
end

def test_should_verify_successfully_if_expected_call_was_made_expected_number_of_times
Expand Down

0 comments on commit 4dea01a

Please sign in to comment.