[rspec-users] Why stop using mock_model in scaffold controller spec?

Mike Mazur mmazur at gmail.com
Tue Mar 27 14:24:28 UTC 2012


On Tue, Mar 27, 2012 at 22:10, Mike Mazur <mmazur at gmail.com> wrote:
> In May last year, the controller specs generated with `rspec g
> scaffold` were changed to use real model objects instead of
> `mock_model`.
> I'm curious why this change was made?

As soon I sent this email off, I noticed this text in the template:

# Compared to earlier versions of this generator, there is very limited use of
# stubs and message expectations in this spec.  Stubs are only used when there
# is no simpler way to get a handle on the object needed for the example.
# Message expectations are only used when there is no simpler way to specify
# that an instance is receiving a specific message.

That explains things a bit, but I'm still curious!

One might argue that the earlier approach (with `mock_model`) may be
better for at least two reasons:

- looser coupling between specs and models
- faster spec execution (ie: don't have to create a real ActiveRecord instance)

I imagine RSpec is treading the fine line between ideal "best
practices" (ie: minimize coupling) and being more pragmatic and easier
to understand by the average developer. What's the current thinking on
this topic?


More information about the rspec-users mailing list