class RSpec::Mocks::MessageExpectation

def and_yield(*args, &block)

stream.stub(:open).and_yield(StringIO.new)

@example

is received.
Tells the object to yield one or more args to a block when the message
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