class FlexMock::CountValidator
Base class for all the count validators.
Public Class Methods
Source
# File lib/flexmock/validators.rb, line 24 def initialize(expectation, limit) @exp = expectation @limit = limit end
Public Instance Methods
Source
# 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
Human readable description of the validator
Source
# File lib/flexmock/validators.rb, line 50 def describe_limit @limit.to_s end
Source
# File lib/flexmock/validators.rb, line 32 def eligible?(n) n < @limit end
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.
Source
# File lib/flexmock/validators.rb, line 57 def validate_count(n, &block) unless yield raise ValidationFailed, construct_validation_count_error_message(n) end end
Private Instance Methods
Source
# File lib/flexmock/validators.rb, line 74 def calls(n) n == 1 ? "call" : "calls" end
Pluralize “call”
Source
# File lib/flexmock/validators.rb, line 66 def construct_validation_count_error_message(n) "Method '#{@exp}' called incorrect number of times\n" + "#{describe_limit} matching #{calls(@limit)} expected\n" + "#{n} matching #{calls(n)} found\n" + describe_calls(@exp.mock) end
Build the error message for an invalid count