Properly yielding responses in Rspec
We had some problem with configuring response that should be yielded to block… after a short investigation, here are outcomes
allow(collection).to receive(:each).and_yield([1, 2])
will yield array ([1, 2]
) to one block variable
allow(collection).to receive(:each).and_yield(1, 2)
will yield two values (1, 2
) to two block variables
allow(collection).to receive(:each).and_yield(1).and_yield(2)
will yield two consecutive values (1, 2
) to one block variable, twice