Sha256: eb9f24ea136a38fd03bd6867aa208b1fa0d260c0a7de5f993d710f3c3d723c41

Contents?: true

Size: 1.17 KB

Versions: 22

Compression:

Stored size: 1.17 KB

Contents

module RR
  module Expectations
    class TimesCalledExpectation #:nodoc:
      attr_reader :double, :times_called

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

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

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

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

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

      def terminal?
        times_matcher.terminal?
      end

    protected
      def times_matcher
        double.definition.times_matcher
      end

      def verify_input_error
        raise RR::Errors.build_error(:TimesCalledError, error_message)
      end

      def error_message
        "#{double.formatted_name}\n#{times_matcher.error_message(@times_called)}"
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rr-3.1.1 lib/rr/expectations/times_called_expectation.rb
rr-3.1.0 lib/rr/expectations/times_called_expectation.rb
rr-3.0.9 lib/rr/expectations/times_called_expectation.rb
rr-3.0.8 lib/rr/expectations/times_called_expectation.rb
rr-3.0.7 lib/rr/expectations/times_called_expectation.rb
rr-3.0.6 lib/rr/expectations/times_called_expectation.rb
rr-3.0.5 lib/rr/expectations/times_called_expectation.rb
rr-3.0.4 lib/rr/expectations/times_called_expectation.rb
rr-3.0.3 lib/rr/expectations/times_called_expectation.rb
rr-3.0.2 lib/rr/expectations/times_called_expectation.rb
rr-3.0.1 lib/rr/expectations/times_called_expectation.rb
rr-3.0.0 lib/rr/expectations/times_called_expectation.rb
rr-1.2.1 lib/rr/expectations/times_called_expectation.rb
rr-1.2.0 lib/rr/expectations/times_called_expectation.rb
rr-1.1.2 lib/rr/expectations/times_called_expectation.rb
rr-1.1.2.rc1 lib/rr/expectations/times_called_expectation.rb
rr-1.1.1 lib/rr/expectations/times_called_expectation.rb
rr-1.1.1.rc1 lib/rr/expectations/times_called_expectation.rb
rr-1.1.0 lib/rr/expectations/times_called_expectation.rb
rr-1.1.0.rc3 lib/rr/expectations/times_called_expectation.rb