Class: RSpec::Mocks::OrderGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/order_group.rb

Instance Method Summary (collapse)

Constructor Details

- (OrderGroup) initialize



5
6
7
8
9
# File 'lib/rspec/mocks/order_group.rb', line 5

def initialize
  @expectations = []
  @invocation_order = []
  @index = 0
end

Instance Method Details

- (Object) clear



48
49
50
51
52
# File 'lib/rspec/mocks/order_group.rb', line 48

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

- (Object) consume



26
27
28
29
30
31
32
33
34
# File 'lib/rspec/mocks/order_group.rb', line 26

def consume
  remaining_expectations.each_with_index do |expectation, index|
    if expectation.ordered?
      @index += index + 1
      return expectation
    end
  end
  nil
end

- (Boolean) empty?



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

def empty?
  @expectations.empty?
end

- (Object) handle_order_constraint(expectation)



37
38
39
40
41
# 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

- (Object) invoked(message)



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

def invoked(message)
  @invocation_order << message
end

- (Boolean) ready_for?(expectation)



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

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

- (Object) register(expectation)



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

def register(expectation)
  @expectations << expectation
end

- (Object) verify_invocation_order(expectation)



43
44
45
46
# 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