class FlexMock::CountValidator

Base class for all the count validators.

Public Class Methods

new(expectation, limit) click to toggle source
# File lib/flexmock/validators.rb, line 23
def initialize(expectation, limit)
  @exp = expectation
  @limit = limit
end

Public Instance Methods

calls(n) click to toggle source

Pluralize "call"

# File lib/flexmock/validators.rb, line 36
def calls(n)
  n == 1 ? "call" : "calls"
end
describe() click to toggle source

Human readable description of the validator

# File lib/flexmock/validators.rb, line 41
def describe
  case @limit
  when 0
    ".never"
  when 1
    ".once"
  when 2
    ".twice"
  else
    ".times(#{@limit})"
  end
end
describe_limit() click to toggle source
# File lib/flexmock/validators.rb, line 54
def describe_limit
  @limit.to_s
end
eligible?(n) click to toggle source

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.

# File lib/flexmock/validators.rb, line 31
def eligible?(n)
  n < @limit
end
validate_count(n, &block) click to toggle source
# File lib/flexmock/validators.rb, line 58
def validate_count(n, &block)
  @exp.flexmock_location_filter do
    FlexMock.framework_adapter.make_assertion(
      lambda {
        "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)
      }, &block)
  end
end