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

Chris Olsen lists at ruby-forum.com
Tue Oct 16 12:48:12 EDT 2007


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", but will
the actual method within the model be called, or does it also create a
stub to allow for the separation with the model.

The reason that I ask is that in the following line "post :create, ..."
there are no params passed into the post, yet is passes even though
there are many validates_presence_of constraints within the model.

The reason for the confusion is that in a previous project I had
failures on many of the auto-generated controller tests and the only way
to make them pass was to ensure all the controller post and put tests
used a model that satisfied all the constraints. On the current project
all the tests are passing when using mock models with no attributes set.

Thanks for the help
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list