module RSpec::Mocks::Methods
def stub_chain(*chain, &blk)
== Examples
composable interfaces.
Stubs a chain of methods. Especially useful with fluent and/or
double.stub_chain(:foo, :bar) { :baz }
double.stub_chain("foo.bar") { :baz }
:call-seq:
def stub_chain(*chain, &blk) chain, blk = format_chain(*chain, &blk) if chain.length > 1 if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, chain[0].to_sym) chain.shift matching_stub.invoke.stub_chain(*chain, &blk) else next_in_chain = Object.new stub(chain.shift) { next_in_chain } next_in_chain.stub_chain(*chain, &blk) end else stub(chain.shift, &blk) end end