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

Jarkko Laine jarkko at jlaine.net
Tue Dec 4 03:33:11 EST 2007


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

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi




More information about the rspec-users mailing list