class RSpec::Mocks::OrderGroup

@private

Public Class Methods

new() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 5
def initialize
  @expectations = []
  @invocation_order = []
  @index = 0
end

Public Instance Methods

clear() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 48
def clear
  @index = 0
  @invocation_order.clear
  @expectations.clear
end
consume() click to toggle source

@private

# File lib/rspec/mocks/order_group.rb, line 26
def consume
  remaining_expectations.each_with_index do |expectation, index|
    next unless expectation.ordered?

    @index += index + 1
    return expectation
  end
  nil
end
empty?() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 54
def empty?
  @expectations.empty?
end
handle_order_constraint(expectation) click to toggle source

@private

# File lib/rspec/mocks/order_group.rb, line 37
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
invoked(message) click to toggle source
# File lib/rspec/mocks/order_group.rb, line 16
def invoked(message)
  @invocation_order << message
end
ready_for?(expectation) click to toggle source

@private

# File lib/rspec/mocks/order_group.rb, line 21
def ready_for?(expectation)
  remaining_expectations.find(&:ordered?) == expectation
end
register(expectation) click to toggle source

@private

# File lib/rspec/mocks/order_group.rb, line 12
def register(expectation)
  @expectations << expectation
end
verify_invocation_order(expectation) click to toggle source
# File lib/rspec/mocks/order_group.rb, line 43
def verify_invocation_order(expectation)
  expectation.raise_out_of_order_error unless expectations_invoked_in_order?
  true
end

Private Instance Methods

expectation_for(message) click to toggle source
# File lib/rspec/mocks/order_group.rb, line 76
def expectation_for(message)
  @expectations.find { |e| message == e }
end
expectations_invoked_in_order?() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 64
def expectations_invoked_in_order?
  invoked_expectations == expected_invocations
end
expected_invocations() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 72
def expected_invocations
  @invocation_order.map { |invocation| expectation_for(invocation) }.compact
end
invoked_expectations() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 68
def invoked_expectations
  @expectations.select { |e| e.ordered? && @invocation_order.include?(e) }
end
remaining_expectations() click to toggle source
# File lib/rspec/mocks/order_group.rb, line 60
def remaining_expectations
  @expectations[@index..-1] || []
end