Class: RR::Expectations::TimesCalledExpectation

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/expectations/times_called_expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(times = nil, &time_condition_block) ⇒ TimesCalledExpectation

Returns a new instance of TimesCalledExpectation.

Raises:

  • (ArgumentError)


6
7
8
9
10
# File 'lib/rr/expectations/times_called_expectation.rb', line 6

def initialize(times=nil, &time_condition_block)
  raise ArgumentError, "Cannot pass in both an argument and a block" if times && time_condition_block
  @times = times || time_condition_block
  @times_called = 0
end

Instance Attribute Details

#timesObject (readonly)

Returns the value of attribute times.



4
5
6
# File 'lib/rr/expectations/times_called_expectation.rb', line 4

def times
  @times
end

#times_calledObject (readonly)

Returns the value of attribute times_called.



4
5
6
# File 'lib/rr/expectations/times_called_expectation.rb', line 4

def times_called
  @times_called
end

Instance Method Details

#verifyObject



19
20
21
22
23
24
# File 'lib/rr/expectations/times_called_expectation.rb', line 19

def verify
  return true if @times.is_a?(Integer) && @times == @times_called
  return true if @times.is_a?(Proc) && @times.call(@times_called)
  return true if @times.is_a?(Range) && @times.include?(@times_called)
  return false
end

#verify!Object



26
27
28
# File 'lib/rr/expectations/times_called_expectation.rb', line 26

def verify!
  raise Errors::TimesCalledError unless verify
end

#verify_inputObject



12
13
14
15
16
17
# File 'lib/rr/expectations/times_called_expectation.rb', line 12

def verify_input
  @times_called += 1
  verify_input_error if @times.is_a?(Integer) && @times_called > @times
  verify_input_error if @times.is_a?(Range) && @times_called > @times.end
  return
end