Advantage of using mock_model() over stub()

What's the advantage of using mock_model() over stub() for a view
spec? It seems like you would want to use the stub() if you are using
a outside-in methodology since you probably haven't even generated
your model yet.

With mock_model you'll get a mock-object that automatically has an
unique 'id' defined, a 'to_params' method, and a 'new_record?' method
(that returns false). Here's an example of the difference between the

@user = mock('User', :id => 10, :new_record? => false, :login =>


@user = mock_model(User, :login => 'nicholas')

Mock_model is a convenience, and as you point out in a view-spec where
you might not have the model created yet it might make sense to go
without. However, you'll see on the RSpec examples (
writing/views.html) that they show them using mock_model. I think
it's your preference. It isn't difficult to generate an empty model
class as a placeholder for the future while you're writing your view.
If I know I'm showing user information on a view, then I can probably
assume I'll be utilizing a User model of some type.

Remember with a outside-in approach you want to go in and out. Dive
in, come up for air, rinse and repeat. It isn't that you want to bang
out your entire view in one session, then your controller then model.
You want to work on smaller slices and iterate and increment.