Skip to content

Commit

Permalink
Expand documentation of cardinality methods.
Browse files Browse the repository at this point in the history
By translating all other cardinality methods to the times method, we
clarify both that all the other methods are merely syntactic sugar, and
that they all set the lower and upper limits to the number of calls.

Closes freerange#476
  • Loading branch information
nitishr committed Mar 23, 2020
1 parent 4c8984f commit 41ad165
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/mocha/expectation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Mocha
class Expectation
# Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
#
# @param [Range,Integer] range specifies the allowable range in the number of expected invocations.
# @param [Range,Integer] range specifies the allowable number or range in the number of expected invocations.
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
#
# @example Specifying a specific number of expected invocations.
Expand Down Expand Up @@ -47,7 +47,7 @@ def times(range)
self
end

# Modifies expectation so that the expected method must be called exactly twice.
# Modifies expectation so that the expected method must be called exactly twice. Has the same effect as calling {times}(2).
#
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
#
Expand All @@ -72,7 +72,7 @@ def twice
times(2)
end

# Modifies expectation so that the expected method must be called exactly once.
# Modifies expectation so that the expected method must be called exactly once. Has the same effect as calling {times}(1).
#
# Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis.
#
Expand All @@ -96,7 +96,7 @@ def once
times(1)
end

# Modifies expectation so that the expected method must never be called.
# Modifies expectation so that the expected method must never be called. Has the same effect as calling {times}(0).
#
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
#
Expand All @@ -112,7 +112,8 @@ def never
times(0)
end

# Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
# Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+ and at most any number of times.
# Has the same effect as calling {times}(+minimum_number_of_times+..Float::INFINITY).
#
# @param [Integer] minimum_number_of_times minimum number of expected invocations.
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
Expand All @@ -132,7 +133,8 @@ def at_least(minimum_number_of_times)
self
end

# Modifies expectation so that the expected method must be called at least once.
# Modifies expectation so that the expected method must be called at least once and at most any number of times.
# Has the same effect as calling {at_least}(1).
#
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
#
Expand All @@ -149,7 +151,8 @@ def at_least_once
at_least(1)
end

# Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
# Modifies expectation so that the expected method must be called from never to at most a +maximum_number_of_times+.
# Has the same effect as calling {times}(0..+maximum_number_of_times+).
#
# @param [Integer] maximum_number_of_times maximum number of expected invocations.
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
Expand All @@ -167,7 +170,8 @@ def at_most(maximum_number_of_times)
times(0..maximum_number_of_times)
end

# Modifies expectation so that the expected method must be called at most once.
# Modifies expectation so that the expected method must be called from never to at most once.
# Has the same effect as calling {at_most}(1).
#
# @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
#
Expand Down

0 comments on commit 41ad165

Please sign in to comment.