RSpec mocks can return multiple values.
allow(die).to receive(:roll).and_return(1, 2, 3)
How to return a dynamic value such as:
allow(clock).to receive(:time).and_return Time.now.to_i
Always returns the first value.
Is it possible to have it evaluate the expression for each call to time
?
Just remove and_return
and pass in block:
allow(clock).to receive(:time) do
Time.now.to_i
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With