@private
# File lib/rspec/mocks/message_chain.rb, line 7 def initialize(object, *chain, &blk) @object = object @chain, @block = format_chain(*chain, &blk) end
@api private
# 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
# File lib/rspec/mocks/message_chain.rb, line 37 def chain_on(object, *chain, &block) initialize(object, *chain, &block) setup_chain end
# File lib/rspec/mocks/message_chain.rb, line 33 def expectation(object, message, &return_block) raise NotImplementedError.new end
# File lib/rspec/mocks/message_chain.rb, line 58 def find_matching_expectation ::RSpec::Mocks.space.proxy_for(object). __send__(:find_matching_expectation, chain.first.to_sym) end
# File lib/rspec/mocks/message_chain.rb, line 53 def find_matching_stub ::RSpec::Mocks.space.proxy_for(object). __send__(:find_matching_method_stub, chain.first.to_sym) end
# File lib/rspec/mocks/message_chain.rb, line 42 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