Class: RR::Expectations::TimesCalledExpectation
- Inherits:
-
Object
- Object
- RR::Expectations::TimesCalledExpectation
- Defined in:
- lib/rr/expectations/times_called_expectation.rb
Instance Attribute Summary collapse
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
-
#times_called ⇒ Object
readonly
Returns the value of attribute times_called.
Instance Method Summary collapse
- #attempt! ⇒ Object
- #attempt? ⇒ Boolean
-
#initialize(matcher = nil, &time_condition_block) ⇒ TimesCalledExpectation
constructor
A new instance of TimesCalledExpectation.
- #verify ⇒ Object
- #verify! ⇒ Object
Constructor Details
#initialize(matcher = nil, &time_condition_block) ⇒ TimesCalledExpectation
Returns a new instance of TimesCalledExpectation.
6 7 8 9 10 11 12 |
# File 'lib/rr/expectations/times_called_expectation.rb', line 6 def initialize(matcher=nil, &time_condition_block) raise ArgumentError, "Cannot pass in both an argument and a block" if matcher && time_condition_block matcher_value = matcher || time_condition_block @matcher = TimesCalledMatchers::TimesCalledMatcher.create(matcher_value) @times_called = 0 @verify_backtrace = caller[1..-1] end |
Instance Attribute Details
#matcher ⇒ Object (readonly)
Returns the value of attribute matcher.
4 5 6 |
# File 'lib/rr/expectations/times_called_expectation.rb', line 4 def matcher @matcher end |
#times_called ⇒ Object (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
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
14 15 16 |
# File 'lib/rr/expectations/times_called_expectation.rb', line 14 def attempt? @matcher.attempt?(@times_called) end |
#verify ⇒ Object
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.backtrace = @verify_backtrace raise error else raise Errors::TimesCalledError, end end end |