在 rpsec-mocks 的 README 这样写
double.should_receive(:msg).and_yield(values,to,yield)
double.should_receive(:msg).and_yield(values,to,yield).and_yield(some,other,values,this,time)
# for methods that yield to a block multiple times
看不明白是什么意思,values
,to
,yield
分别是什么?
Source 是这样:
# Tells the object to yield one or more args to a block when the message
# is received.
#
# @example
#
# stream.stub(:open).and_yield(StringIO.new)
def and_yield(*args, &block)
if @args_to_yield_were_cloned
@args_to_yield.clear
@args_to_yield_were_cloned = false
end
if block
@eval_context = Object.new
@eval_context.extend RSpec::Mocks::InstanceExec
yield @eval_context
end
@args_to_yield << args
self
end