123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Mocks::MessageChain Private

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
RSpec::Mocks::ExpectChain, RSpec::Mocks::StubChain
Inherits: Object
Defined in: rspec-mocks/lib/rspec/mocks/message_chain.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#block (readonly)

[ GitHub ]

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

attr_reader :object, :chain, :block

#chain (readonly)

[ GitHub ]

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

attr_reader :object, :chain, :block

#object (readonly)

[ GitHub ]

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

attr_reader :object, :chain, :block

Instance Method Details

#chain_on(object, *chain, &block) (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/message_chain.rb', line 33

def chain_on(object, *chain, &block)
  initialize(object, *chain, &block)
  setup_chain
end

#find_matching_expectation (private)

[ GitHub ]

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

def find_matching_expectation
  ::RSpec::Mocks.space.proxy_for(object).
    __send__(:find_matching_expectation, chain.first.to_sym)
end

#find_matching_stub (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/message_chain.rb', line 49

def find_matching_stub
  ::RSpec::Mocks.space.proxy_for(object).
    __send__(:find_matching_method_stub, chain.first.to_sym)
end

#format_chain(*chain, &blk) (private)

[ GitHub ]

  
# File 'rspec-mocks/lib/rspec/mocks/message_chain.rb', line 38

def format_chain(*chain, &blk)
  if Hash === chain.last
    hash = chain.pop
    hash.each do |k, v|
      chain << k
      blk = Proc.new { v }
    end
  end
  return chain.join('.').split('.'), blk
end

#setup_chain

[ GitHub ]

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