[rspec-devel] Mocking in the past tense

Jay Levitt lists-rspec at shopwatch.org
Thu Nov 16 13:28:26 EST 2006

David Chelimsky wrote:
> The idea of past-tense mocking has come up before. The problem is that
> it only provides value in a very limited subset of potential uses.
> So, for me, I'd rather absorb the subtle dampness of the do_get method
> and keep the specs clear.

Good point - there's no way to post-specify what a mock should have 

I guess the problem I have is in the disconnect between the English 
specification and the code.  I'm finding specs that look like this:

context "/controller/login" do
   setup do
     u = mock("User")

   specify "should redirect if login fails" do
     post "login", :user => "louie", :password => "xxx"

   specify "should render welcome if login succeeds" do
     post "login", ...


What feels icky about this - whether I do mock_the_model in setup or in 
each spec - is that I never have a spec that explicitly outlines the 
"shoulds" that are specified as part of mocking.  In controllers, 
especially, this seems to be the key part of the spec.  In the spec 
above, there's only a single model verb that's mocked, but more complex 
controllers will obviously do more work.

I find myself writing a bunch of "null specs" - that is, specs that do 
nothing but the mocking - to overcome that.  But then I have to 
intentionally leave out some portion of the mock so that the mock 
corresponds with the English.  It doesn't feel right, but I can't quite 
put my finger on what would feel better.


More information about the rspec-devel mailing list