title: Testing methods called on yielded object
body: <p>I have the following controller test case:</p>
  
  <pre><code>def test_showplain
    Cleaner.expect(:parse).with(@somecontent)
    Cleaner.any_instance.stubs(:plainversion).returns(@returnvalue)
  
    post :showplain, {:content =&gt; @somecontent}
  
  end
  </code></pre>
  
  <p>This works fine, except that I want the "stubs(:plainversion)" to be an "expects(:plainversion)".</p>
  
  <p>Here's the controller code:</p>
  
  <pre><code>def showplain
     Cleaner.parse(params[:content]) do | cleaner |
        @output = cleaner.plainversion
     end
  end
  </code></pre>
  
  <p>And the Cleaner is simply:</p>
  
  <pre><code>class Cleaner
  
     ### other code and methods ###
  
     def self.parse(@content) 
       cleaner = Cleaner.new(@content)
       yield cleaner
       cleaner.close
     end
  
     def plainversion
        ### operate on @content and return ###
     end
  
  end
  </code></pre>
  
  <p>Again, I can't figure out how to reliably test the "cleaner" that is made available from the "parse" method. Any suggestions?</p>