Can RSpec stubbed method return different values in sequence?

You can stub a method to return different values each time it’s called;

allow(@family).to receive(:location).and_return('first', 'second', 'other')

So the first time you call @family.location it will return ‘first’, the second time it will return ‘second’, and all subsequent times you call it, it will return ‘other’.

Leave a Comment