Sha256: 38bbc517a2a40e2759b0cef685806d326d72b2134b0041501c39eafe3b2b1669

Contents?: true

Size: 1.01 KB

Versions: 61

Compression:

Stored size: 1.01 KB

Contents

module Mocha

  # Used to constrain the order in which expectations can occur.
  #
  # @see API#sequence
  # @see Expectation#in_sequence
  class Sequence

    # @private
    class InSequenceOrderingConstraint

      def initialize(sequence, index)
        @sequence, @index = sequence, index
      end

      def allows_invocation_now?
        @sequence.satisfied_to_index?(@index)
      end

      def mocha_inspect
        "in sequence #{@sequence.mocha_inspect}"
      end

    end

    # @private
    def initialize(name)
      @name = name
      @expectations = []
    end

    # @private
    def constrain_as_next_in_sequence(expectation)
      index = @expectations.length
      @expectations << expectation
      expectation.add_ordering_constraint(InSequenceOrderingConstraint.new(self, index))
    end

    # @private
    def satisfied_to_index?(index)
      @expectations[0...index].all? { |expectation| expectation.satisfied? }
    end

    # @private
    def mocha_inspect
      "#{@name.mocha_inspect}"
    end

  end

end

Version data entries

61 entries across 50 versions & 5 rubygems

Version Path
mocha-1.6.0 lib/mocha/sequence.rb
mocha-1.5.0 lib/mocha/sequence.rb
mocha-1.4.0 lib/mocha/sequence.rb
mocha-1.3.0 lib/mocha/sequence.rb
mocha-1.2.1 lib/mocha/sequence.rb
mocha-1.2.0 lib/mocha/sequence.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/sequence.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/sequence.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/mocha-1.0.0/lib/mocha/sequence.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/mocha-1.0.0/lib/mocha/sequence.rb
mocha-1.1.0 lib/mocha/sequence.rb
mocha-1.0.0 lib/mocha/sequence.rb
mocha-1.0.0.alpha lib/mocha/sequence.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/sequence.rb
challah-1.0.0 vendor/bundle/gems/mocha-0.14.0/lib/mocha/sequence.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/mocha-0.14.0/lib/mocha/sequence.rb
mocha-0.14.0 lib/mocha/sequence.rb
challah-1.0.0.beta3 vendor/bundle/gems/mocha-0.13.3/lib/mocha/sequence.rb
mocha-0.14.0.alpha lib/mocha/sequence.rb
challah-1.0.0.beta2 vendor/bundle/gems/mocha-0.13.3/lib/mocha/sequence.rb