Skip to content

Commit

Permalink
Refactor: prep to turn class methods into instance
Browse files Browse the repository at this point in the history
... in order to make a single Cardinality instance persist across
updates to expectation cardinality. This include a 'times' method. To
make space for it, the existing protected 'times' method has been
renamed to 'count'.
  • Loading branch information
nitishr committed Mar 8, 2020
1 parent cc91b87 commit 9d0d37a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/mocha/cardinality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ def anticipated_times
if allowed_any_number_of_times?
'allowed any number of times'
elsif required.zero? && maximum.zero?
"expected #{times(maximum)}"
"expected #{count(maximum)}"
elsif required == maximum
"expected exactly #{times(required)}"
"expected exactly #{count(required)}"
elsif infinite?(maximum)
"expected at least #{times(required)}"
"expected at least #{count(required)}"
elsif required.zero?
"expected at most #{times(maximum)}"
"expected at most #{count(maximum)}"
else
"expected between #{required} and #{times(maximum)}"
"expected between #{required} and #{count(maximum)}"
end
end
# rubocop:enable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity

def invoked_times
"invoked #{times(@invocations.size)}"
"invoked #{count(@invocations.size)}"
end

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

attr_reader :required, :maximum

def times(number)
def count(number)
case number
when 0 then 'never'
when 1 then 'once'
Expand Down

0 comments on commit 9d0d37a

Please sign in to comment.