title: RSpec retry throw exception and then return value
body: <p>I have a retry block</p>
  
  <pre><code> def my_method
      app_instances = []
      attempts = 0
      begin 
        app_instances = fetch_and_rescan_app_instances(page_n, policy_id, policy_cpath)
      rescue Exception
        attempts += 1
        retry unless attempts &gt; 2
        raise Exception 
      end
      page_n += 1
    end
  </code></pre>
  
  <p>where <code>fetch_and_rescan_app_instances</code> access the network so can throw an exception.</p>
  
  <p>I want to write an rspec test that it throws an exception first time and doesn't throw an exception second time it gets called, so I can test if the second time it doesn't throw an exception, the my_method won't throw an exeption.</p>
  
  <p>I know i can do <code>stub(:fetch_and_rescan_app_instances).and_return(1,3)</code> and first time it returns 1 and second time 3, but I don't know how to do throw an exception first time and return something second time.</p>