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
Instance Method Summary collapse
-
#describe ⇒ Object
Human readable description of the validator.
- #describe_limit ⇒ Object
-
#eligible?(n) ⇒ Boolean
If the expectation has been called
ntimes, 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
#describe_spy_expectation, #describe_spy_negative_expectation, #spy_description
Constructor Details
#initialize(expectation, limit) ⇒ CountValidator
23 24 25 26 |
# File 'lib/flexmock/validators.rb', line 23 def initialize(expectation, limit) @exp = expectation @limit = limit end |
Instance Method Details
#describe ⇒ Object
Human readable description of the validator
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flexmock/validators.rb', line 36 def describe case @limit when 0 ".never" when 1 ".once" when 2 ".twice" else ".times(#{@limit})" end end |
#describe_limit ⇒ Object
49 50 51 |
# File 'lib/flexmock/validators.rb', line 49 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.
31 32 33 |
# File 'lib/flexmock/validators.rb', line 31 def eligible?(n) n < @limit end |
#validate_count(n, &block) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/flexmock/validators.rb', line 53 def validate_count(n, &block) @exp.flexmock_location_filter do FlexMock.framework_adapter.make_assertion( lambda { (n) }, &block) end end |