Sha256: a554a4552eaecff53499894444da26c647e0d499b6df83609fc65aff31eecd45

Contents?: true

Size: 1.81 KB

Versions: 7098

Compression:

Stored size: 1.81 KB

Contents

module RSpec
  module Mocks
    # @private
    class OrderGroup
      def initialize
        @expectations = []
        @invocation_order = []
        @index = 0
      end

      # @private
      def register(expectation)
        @expectations << expectation
      end

      def invoked(message)
        @invocation_order << message
      end

      # @private
      def ready_for?(expectation)
        remaining_expectations.find(&:ordered?) == expectation
      end

      # @private
      def consume
        remaining_expectations.each_with_index do |expectation, index|
          next unless expectation.ordered?

          @index += index + 1
          return expectation
        end
        nil
      end

      # @private
      def handle_order_constraint(expectation)
        return unless expectation.ordered? && remaining_expectations.include?(expectation)
        return consume if ready_for?(expectation)
        expectation.raise_out_of_order_error
      end

      def verify_invocation_order(expectation)
        expectation.raise_out_of_order_error unless expectations_invoked_in_order?
        true
      end

      def clear
        @index = 0
        @invocation_order.clear
        @expectations.clear
      end

      def empty?
        @expectations.empty?
      end

    private

      def remaining_expectations
        @expectations[@index..-1] || []
      end

      def expectations_invoked_in_order?
        invoked_expectations == expected_invocations
      end

      def invoked_expectations
        @expectations.select { |e| e.ordered? && @invocation_order.include?(e) }
      end

      def expected_invocations
        @invocation_order.map { |invocation| expectation_for(invocation) }.compact
      end

      def expectation_for(message)
        @expectations.find { |e| message == e }
      end
    end
  end
end

Version data entries

7,098 entries across 7,007 versions & 130 rubygems

Version Path
affixapi-1.1.102 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.0/lib/rspec/mocks/order_group.rb
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/rspec-mocks-3.11.1/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_id_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_id_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_id_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_id_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
ory-client-1.15.12 vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_id_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_bank_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb
cybrid_api_organization_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/rspec-mocks-3.13.2/lib/rspec/mocks/order_group.rb