[rspec-users] help with rspec'ing controller

Steve Odom steve.odom at gmail.com
Tue May 8 12:05:20 EDT 2007


Thanks Aslak and Michael.

You were both right. Changing save! to save in my second context made  
that test pass.

Michael also mentioned...
 >First concern is that your mock objects got stubbed after it is
 >returned by new method stub. I alway tend to prepair mock/stub
 >completely before I use it as argument or any other way.

I'm not sure what you mean by prepair mock/stub completely. Can you  
provide a sample of how you would rspec a simple create action, such as:

def create
     @product = Product.new(params[:product])
     if @product.save
       flash[:notice] = 'Product was successfully created.'
       redirect_to :action => 'list'
     else
       render :action => 'new'
     end
   end


 >Second is that tyou try to check that your controller's setup creates
 >a valid product, but you use mocks, it's up to you to decide whether
 >your model is valid or not, what it expects to receive and what it
 >returns. It looks like you get this idea from your models specs where
 >such a check is useful.

I might be misunderstanding you, but I thought it was preferable to  
mock/stub all the ActiveRecord instances in your controller and only  
focus on the controller responsibilities.

thanks for the help.

Steve

On May 8, 2007, at 10:43 AM, Michael Klishin wrote:

> t

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070508/4cb7eba5/attachment.html 


More information about the rspec-users mailing list