class RSpec::Mocks::StubChain

def stub_chain

def stub_chain
  if chain.length > 1
    if matching_stub = find_matching_stub
      chain.shift
      matching_stub.invoke(nil).stub_chain(*chain, &block)
    else
      next_in_chain = Mock.new
      object.stub(chain.shift) { next_in_chain }
      StubChain.stub_chain_on(next_in_chain, *chain, &block)
    end
  else
    object.stub(chain.shift, &block)
  end
end