Forum: RSpec [rspec, rails] Restful Routes in controller specs

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
09bd90b495a8456dede9cc2fea4f3aec?d=identicon&s=25 Andi Schacke (schacke)
on 2009-03-11 10:03
(Received via mailing list)
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
5d38ab152e1e3e219512a9859fcd93af?d=identicon&s=25 David Chelimsky (Guest)
on 2009-03-11 14:41
(Received via mailing list)
On Wed, Mar 11, 2009 at 3:30 AM, Andi Schacke
<memberships.andi@gmail.com> 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...

If you're asking how to do it, you just do. There's nothing you have
to do. They're there for free.

If you're asking how they are there for free, controllers specs wrap
rails functional tests, so they have all the services provided by
rails.

Cheers,
David
387fb00ef9d6d523d43018d9c81ab36b?d=identicon&s=25 Jonathan Linowes (Guest)
on 2009-03-11 14:46
(Received via mailing list)
On Mar 11, 2009, at 4:30 AM, Andi Schacke wrote:

> rspec-users mailing list
> rspec-users@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
    end
  end

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

    it "should route /users/:id" do
           user_path('123').should == '/users/123'
           params_from(:get, '/users/123').should == {:controller =>
'users', :action => 'show', :id => '123'}
       end
  end
09bd90b495a8456dede9cc2fea4f3aec?d=identicon&s=25 Andi Schacke (schacke)
on 2009-03-11 15:44
(Received via mailing list)
Thanks a lot David, my question was 'how' they are for free. That
explains why I didn't find it in the rspec-rails sourcecode.

Cheers
Andi
This topic is locked and can not be replied to.