Forum: RSpec dealing with a retry inside of a rescue block

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joey G. (Guest)
on 2008-11-18 23:22
(Received via mailing list)
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
This topic is locked and can not be replied to.