Class: RSpec::Mocks::MessageChain

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_chain.rb

Direct Known Subclasses

ExpectChain, StubChain

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, *chain, &blk) ⇒ MessageChain

Returns a new instance of MessageChain.



7
8
9
10
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_chain.rb', line 5

def block
  @block
end

#chainObject (readonly)

Returns the value of attribute chain.



5
6
7
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_chain.rb', line 5

def chain
  @chain
end

#objectObject (readonly)

Returns the value of attribute object.



5
6
7
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/lib/rspec/mocks/message_chain.rb', line 5

def object
  @object
end

Instance Method Details

#setup_chainObject

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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rspec-mocks-3.12.2/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