RSpec Stub same method in loop

Viewed 1491

Using RSpec, I want to:

expect(Thing).to receive(:status)
                .with(for: 'something')
                .and_return('down')

on the first iteration, and the same stub should return a different return on the 2nd iteration:

expect(Thing).to receive(:status)
                .with(for: 'something')
                .and_return('up')

when testing the below code snippet:

2.times do |i|
  break if Thing.status(for: 'something') == 'up'
  sleep 2
  raise MyError if i > 0
end

How would I do this?

2 Answers
Related