[rspec-users] params not available for controller specs?

Al Chou hotfusionman at yahoo.com
Tue Dec 4 04:28:40 EST 2007

I actually did stub Order.find() but was getting a nil object error because params[:ids] was nil.  I can't write

controller.download :ids => '1/2/3'

in the controller spec, and

get download, :ids => ids_string

results in the following error message:

NameError in 'Admin::OrdersController should split the params[:ids] string to create an array of id's to find for downloading'
undefined local variable or method `download' for [RSpec example]:#<Class:0x34939e8>

----- Original Message ----
From: Jarkko Laine <jarkko at jlaine.net>
To: rspec-users <rspec-users at rubyforge.org>
Sent: Tuesday, December 4, 2007 12:33:11 AM
Subject: Re: [rspec-users] params not available for controller specs?

On 4.12.2007, at 10.17, Al Chou wrote:

> Hi, all,
> I'm trying to write a spec for a controller method that starts out:
>   def download
>     @orders = Order.find( params[:ids] )
>     ...
> and started writing a spec that set params[:ids] to a mock.

Why would you want to set params[:ids] to a mock? params values are  
always basically strings (or hashes/arrays of strings) and you can set
them in the actual action call:

get :foo, :ids => [1,2,3]

Moreover, in your case Order.find should be the thing you want to  
stub. You don't want the finder call to go to the database, since  
you're speccing the controller behaviour here, not business logic.


Jarkko Laine

rspec-users mailing list
rspec-users at rubyforge.org

Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rspec-users/attachments/20071204/4ad4f71a/attachment.html 

More information about the rspec-users mailing list