title: How do I test yield_control multiple times to a block that raises an error?
body: <p>I'd like to use the <code>yield_control</code> matcher in RSpec like so</p>
  
  <pre><code>expect {|b| some_method(&amp;b) }.to yield_control.exactly(5).times
  </code></pre>
  
  <p>However, I'd like the block to <em>raise an error</em>. Is there an RSpec construct that allows you to do this?</p>
  
  <p>Basically, I'm looking for something like an RSpec mock object that allows you to raise an error whenever the block is yielded to and count the number of times it was yielded to.</p>
  
  <p>I understand there are other ways of doing it by defining my own block that keeps track of how many times it has been called, but I was hoping there is a built-in that does something like this.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>def some_method(&amp;block)
    attempt = 0
    begin
      attempt += 1
      yield
    rescue =&gt; e
      retry if attempt &lt; 3
    end
  end
  </code></pre>
  
  <p>I'd like to test that control is yielded a certain number of times when the block raises an error. I understand that this is one way to do it:</p>
  
  <pre><code>number_of_times = 0
  some_method do
    number_of_times += 1
    raise StandardError
  end
  expect(number_of_times).to eq(3)
  </code></pre>
  
  <p>But I was hoping I could use the <code>expect {..}.to yield_control</code> syntax.</p>