Class: FlexMock::CountValidator

Inherits:
Object
  • Object
show all
Includes:
SpyDescribers
Defined in:
lib/flexmock/validators.rb

Overview

Base class for all the count validators.

Instance Method Summary collapse

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

#describeObject

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_limitObject



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 { construct_validation_count_error_message(n) },
      &block)
  end
end