[rspec-devel] Mocking in the past tense

Jay Levitt lists-rspec at shopwatch.org
Thu Nov 9 22:15:17 EST 2006

I'm in the process of converting my controller specs into TRUE 
controller specs (not just semi-integration specs), and I'm realizing 
that, for the same reason we have controller.should_have_rendered, we 
need mocking in the past tense, or - more likely - a better setup solution.

The common case for a controller spec has

context "/controller/something"
   setup do
     get 'something'

and then a bunch of specs that ensure the 'something' action does what 
it's supposed to.

Well, if you spec this by mocking, instead of specifying state, there's 
really no way to put that "get" into setup. If you did, then all your 
mocks would have to go into setup too - and that means your entire spec 
is in setup.

Right now, I'm solving this by putting the get into a subroutine and 
calling it repeatedly in each spec.  That doesn't feel DRY.  On the 
other hand, I can't think of an improvement that doesn't have at least a 
"yield" in the middle of a spec, and I'm not sure that's such an 

Any thoughts?


More information about the rspec-devel mailing list