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, matcher = nil) ⇒ TimesCalledExpectation

Returns a new instance of TimesCalledExpectation.



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

def initialize(double, matcher=nil)
  @double = double
  @matcher = matcher
  @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

#matcherObject

Returns the value of attribute matcher.



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

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



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

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

#attempt?Boolean

Returns:

  • (Boolean)


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

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

#terminal?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rr/expectations/times_called_expectation.rb', line 41

def terminal?
  @matcher.terminal?
end

#verifyObject



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

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

#verify!Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rr/expectations/times_called_expectation.rb', line 29

def verify!
  unless verify
    if @verify_backtrace
      error = Errors::TimesCalledError.new(error_message)
      error.backtrace = @verify_backtrace
      raise error
    else
      raise Errors::TimesCalledError, error_message
    end
  end
end