Class: RSpec::Mocks::MessageChain

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

Direct Known Subclasses

ExpectChain, StubChain

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (MessageChain) initialize(object, *chain, &blk)



7
8
9
10
# File 'lib/rspec/mocks/message_chain.rb', line 7

def initialize(object, *chain, &blk)
  @object = object
  @chain, @block = format_chain(*chain, &blk)
end

Instance Attribute Details

- (Object) block (readonly)

Returns the value of attribute block



5
6
7
# File 'lib/rspec/mocks/message_chain.rb', line 5

def block
  @block
end

- (Object) chain (readonly)

Returns the value of attribute chain



5
6
7
# File 'lib/rspec/mocks/message_chain.rb', line 5

def chain
  @chain
end

- (Object) object (readonly)

Returns the value of attribute object



5
6
7
# File 'lib/rspec/mocks/message_chain.rb', line 5

def object
  @object
end

Instance Method Details

- (Object) setup_chain

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rspec/mocks/message_chain.rb', line 13

def setup_chain
  if chain.length > 1
    if matching_stub = find_matching_stub
      chain.shift
      chain_on(matching_stub.invoke(nil), *chain, &@block)
    elsif matching_expectation = find_matching_expectation
      chain.shift
      chain_on(matching_expectation.invoke_without_incrementing_received_count(nil), *chain, &@block)
    else
      next_in_chain = Double.new
      expectation(object, chain.shift) { next_in_chain }
      chain_on(next_in_chain, *chain, &@block)
    end
  else
    expectation(object, chain.shift, &@block)
  end
end