Class: RR::Expectations::TimesCalledExpectation

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(double) ⇒ TimesCalledExpectation

Returns a new instance of TimesCalledExpectation.



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

def initialize(double)
  @double = double
  @times_called = 0
  @verify_backtrace = caller[1..-1]
end

Instance Attribute Details

#doubleObject (readonly)

Returns the value of attribute double.



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

def double
  @double
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

#attemptObject



16
17
18
19
20
# File 'lib/rr/expectations/times_called_expectation.rb', line 16

def attempt
  @times_called += 1
  verify_input_error unless times_matcher.possible_match?(@times_called)
  return
end

#attempt?Boolean

Returns:

  • (Boolean)


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

def attempt?
  times_matcher.attempt?(@times_called)
end

#terminal?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/rr/expectations/times_called_expectation.rb', line 33

def terminal?
  times_matcher.terminal?
end

#verifyObject



22
23
24
25
# File 'lib/rr/expectations/times_called_expectation.rb', line 22

def verify
  return false unless times_matcher.is_a?(TimesCalledMatchers::TimesCalledMatcher)
  return times_matcher.matches?(@times_called)
end

#verify!Object



27
28
29
30
31
# File 'lib/rr/expectations/times_called_expectation.rb', line 27

def verify!
  unless verify
    raise RR::Errors.build_error(:TimesCalledError, error_message, @verify_backtrace)
  end
end