[rspec-users] [rspec, rails] Restful Routes in controller specs

Jonathan Linowes jonathan at parkerhill.com
Wed Mar 11 09:35:23 EDT 2009

On Mar 11, 2009, at 4:30 AM, Andi Schacke wrote:

> Hi,
> how is it possible that I can use the restful routes helpers (e.g.
> new_user_path) in controller specs? I browsed the source code but I
> couldn't find the magic. I'm just curious and would appreciate any
> hint...
> thanks
> Andi
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

You can use them -after- the request, eg

	post :create
	response.should redirect_to( foo_path )

You can't before the request because they're not loaded yet.

Actually, I have a routes_spec.rb that goes something like this:

	class FoosController < ApplicationController
		def foo

	describe FoosController, "named routes" do
		before do
	  		get :foo

		it "should route /users/:id" do
     			user_path('123').should == '/users/123'
     			params_from(:get, '/users/123').should == {:controller =>  
'users', :action => 'show', :id => '123'}

More information about the rspec-users mailing list