[rspec-users] 'lazy' url generation in view specs

Ingo Weiss ingo at ingoweiss.com
Thu Nov 15 04:59:04 EST 2007


I would like to use the 'lazy' style of url generation in my views,  
omitting parameters from my calls to url_for (and named route  
methods) that are then filled in from the current request parameters.

url_for(:action => 'index') will fill in (:controller => 'posts') if  
params[:controller] is 'posts'

However, this breaks my view specs because when they render the view  
there is no request from which to fill in the missing parameters. How  
can I stub/mock the request so that the 'lazy' url-generation works  
in view spec? I tried a number of things, none of them working,  
including this:

@controller.stub!(:params).and_return({:controller =>  
'posts', :action => 'show'})


More information about the rspec-users mailing list