123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::OrderGroup Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-mocks/lib/rspec/mocks/order_group.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 54

def empty?
  @expectations.empty?
end

#expectations_invoked_in_order?Boolean (readonly, private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 64

def expectations_invoked_in_order?
  invoked_expectations == expected_invocations
end

Instance Method Details

#clear

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 48

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

#consume

[ GitHub ]

  
# File 'rspec-mocks/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

#expectation_for(message) (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 76

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

#expected_invocations (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 72

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

#handle_order_constraint(expectation)

[ GitHub ]

  
# File 'rspec-mocks/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)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 16

def invoked(message)
  @invocation_order << message
end

#invoked_expectations (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 68

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

#ready_for?(expectation) ⇒ Boolean

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 21

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

#register(expectation)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 12

def register(expectation)
  @expectations << expectation
end

#remaining_expectations (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/order_group.rb', line 60

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

#verify_invocation_order(expectation)

[ GitHub ]

  
# File 'rspec-mocks/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