Sha256: 265515ae91cb4e18c98aa1941c66c2a4e0afd24266411ef45020064dcfb6bc71

Contents?: true

Size: 1.31 KB

Versions: 52

Compression:

Stored size: 1.31 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
          if @verify_backtrace
            error = Errors::TimesCalledError.new(error_message)
            error.backtrace = @verify_backtrace
            raise error
          else
            raise Errors::TimesCalledError, error_message
          end
        end
      end

      def terminal?
        times_matcher.terminal?
      end

      protected
      def times_matcher
        double.definition.times_matcher
      end

      def verify_input_error
        raise Errors::TimesCalledError, error_message
      end

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

Version data entries

52 entries across 48 versions & 9 rubygems

Version Path
adva-0.2.4 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.2.3 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.2.2 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.2.1 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.2.0 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.1.4 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.1.3 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.1.2 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.1.1 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.1.0 test/rr/lib/rr/expectations/times_called_expectation.rb
adva-0.0.1 test/rr/lib/rr/expectations/times_called_expectation.rb
jferris-rr-0.7.1.0.1239654108 lib/rr/expectations/times_called_expectation.rb
redinger-redinger-rr-0.10.3 lib/rr/expectations/times_called_expectation.rb
redinger-rr-0.10.4 lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/expectations/times_called_expectation.rb