4
# Copyright 2003, 2004, 2005, 2006, 2007 by Jim Weirich (jim@weirichhouse.org).
7
# Permission is granted for use, copying, modification, distribution,
8
# and distribution of modified versions of this work as long as the
9
# above copyright notice is included.
12
require 'flexmock/noop'
16
####################################################################
17
# Base class for all the count validators.
20
def initialize(expectation, limit)
25
# If the expectation has been called +n+ times, is it still
26
# eligible to be called again? The default answer compares n to
27
# the established limit.
33
####################################################################
34
# Validator for exact call counts.
36
class ExactCountValidator < CountValidator
37
# Validate that the method expectation was called exactly +n+
40
FlexMock.framework_adapter.assert_equal @limit, n,
41
"method '#{@exp}' called incorrect number of times"
45
####################################################################
46
# Validator for call counts greater than or equal to a limit.
48
class AtLeastCountValidator < CountValidator
49
# Validate the method expectation was called no more than +n+
52
FlexMock.framework_adapter.assert_block(
53
"Method '#{@exp}' should be called at least #{@limit} times,\n" +
54
"only called #{n} times") { n >= @limit }
57
# If the expectation has been called +n+ times, is it still
58
# eligible to be called again? Since this validator only
59
# establishes a lower limit, not an upper limit, then the answer
66
####################################################################
67
# Validator for call counts less than or equal to a limit.
69
class AtMostCountValidator < CountValidator
70
# Validate the method expectation was called at least +n+ times.
72
FlexMock.framework_adapter.assert_block(
73
"Method '#{@exp}' should be called at most #{@limit} times,\n" +
74
"only called #{n} times") { n <= @limit }