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

Returns a new instance of TimesCalledExpectation.



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

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

Instance Attribute Details

#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

#attempt!Object



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

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

#attempt?Boolean

Returns:

  • (Boolean)


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

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

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal?
  @matcher.terminal?
end

#verifyObject



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

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

#verify!Object



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

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