Class: FlexMock::CountValidator
- Includes:
- SpyDescribers
- Defined in:
- lib/flexmock/validators.rb
Overview
Base class for all the count validators.
Direct Known Subclasses
AtLeastCountValidator, AtMostCountValidator, ExactCountValidator
Defined Under Namespace
Classes: ValidationFailed
Instance Method Summary collapse
-
#describe ⇒ Object
Human readable description of the validator.
- #describe_limit ⇒ Object
-
#eligible?(n) ⇒ Boolean
If the expectation has been called
n
times, is it still eligible to be called again? The default answer compares n to the established limit. -
#initialize(expectation, limit) ⇒ CountValidator
constructor
A new instance of CountValidator.
- #validate_count(n, &block) ⇒ Object
Methods included from SpyDescribers
#append_call_record, #block_description, #describe_calls, #describe_spy, #describe_spy_expectation, #describe_spy_negative_expectation, #spy_description, #times_description
Constructor Details
#initialize(expectation, limit) ⇒ CountValidator
Returns a new instance of CountValidator.
24 25 26 27 |
# File 'lib/flexmock/validators.rb', line 24 def initialize(expectation, limit) @exp = expectation @limit = limit end |
Instance Method Details
#describe ⇒ Object
Human readable description of the validator
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flexmock/validators.rb', line 37 def describe case @limit when 0 ".never" when 1 ".once" when 2 ".twice" else ".times(#{@limit})" end end |
#describe_limit ⇒ Object
50 51 52 |
# File 'lib/flexmock/validators.rb', line 50 def describe_limit @limit.to_s end |
#eligible?(n) ⇒ Boolean
If the expectation has been called n
times, is it still eligible to be called again? The default answer compares n to the established limit.
32 33 34 |
# File 'lib/flexmock/validators.rb', line 32 def eligible?(n) n < @limit end |
#validate_count(n, &block) ⇒ Object
57 58 59 60 61 |
# File 'lib/flexmock/validators.rb', line 57 def validate_count(n, &block) unless yield raise ValidationFailed, (n) end end |