Dealing with a retry inside of a rescue block


#1

I’m trying to spec this method which is attempting to connect to
beanstalkd message queue. I’m trying to figure out how to spec this so
it catches the retry without actually retrying the block forever.

Any help would be appreciated.

def get_message(name, peek=false)
begin
if peek
get_queue(name).reserve if get_queue(name).peek_ready
else
get_queue(name).reserve
end
rescue Beanstalk::NotConnected => e
sleep(10)
retry
end
end

   it "should sleep for 10 seconds" do
     queue = mock("queue")
     queue.should_receive(:reserve).and_raise(Beanstalk::NotConnected)
     BeanstalkMessageQueue.should_receive(:get_queue).with('cheese').and_return(queue)
     BeanstalkMessageQueue.should_receive(:sleep).with(10).and_return(true)

#not working
BeanstalkMessageQueue.should_receive(:retry).and_return(false)

     BeanstalkMessageQueue.get_message('cheese')
   end