Testing methods called on yielded object
- by Todd R
I have the following controller test case:
def test_showplain
Cleaner.expect(:parse).with(@somecontent)
Cleaner.any_instance.stubs(:plainversion).returns(@returnvalue)
post :showplain, {:content => @somecontent}
end
This works fine, except that I want the "stubs(:plainversion)" to be an "expects(:plainversion)".
Here's the controller code:
def showplain
Cleaner.parse(params[:content]) do | cleaner |
@output = cleaner.plainversion
end
end
And the Cleaner is simply:
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
Again, I can't figure out how to reliably test the "cleaner" that is made available from the "parse" method. Any suggestions?