title: how do I test that a ruby proc is called using rspec?
body: <p>I'm trying to test that a proc is called in an rspec spec.  The best I could come up with was this:</p>
  
  <pre><code>my_proc = proc { throw :my_proc_was_called }
  expect {
    my_proc.call
  }.to throw_symbol :my_proc_was_called
  </code></pre>
  
  <p>But this assumes that nothing else will catch my thrown symbol, plus I wouldn't mind a terser way to check arguments than by putting argument matchers inside the proc itself.  With rspec mocks, I can check that an object receives a method and even call the original method after checking the arguments, but I couldn't find any sort of convenience like that for a proc.</p>
  
  <p>Chris Heald suggested just listening that the proc receives <code>call</code> but that breaks down if the block is invoked by yield as in this example:</p>
  
  <pre><code>my_class = Class.new do
    def call_proc
      yield
    end
  end
  my_proc = proc { }
  expect(my_proc).to receive(:call)
  my_class.new.call_proc(&amp;my_proc)
  </code></pre>