[rspec-users] Does a mock model have to satisfy contraints

David Chelimsky dchelimsky at gmail.com
Tue Oct 16 13:00:14 EDT 2007

On 10/16/07, Chris Olsen <lists at ruby-forum.com> wrote:
> I am a little confused to the what happens with the following:
>   before do
>     @site = mock_model(Site, :to_param => "1")
>     Site.stub!(:new).and_return(@site)
>   end
>   def post_with_successful_save
>     @site.should_receive(:save).and_return(true)
>     post :create, :site => {}
>   end
> I understand that the "@site.should_receive(:save)..." places a check to
> whether the method is called and that it should return "true"

This is a bit tricky. What you're setting up here (which is true of
message expectations in general, not must mock_model) is an
expectation that @site will receive the message :save and that when it
does receive it, you are instructing it to return true (not expecting
that the real :save method returns true).

The real :save method is not called.

Make sense?

More information about the rspec-users mailing list