Andi Schacke
2009-Mar-11 08:30 UTC
[rspec-users] [rspec, rails] Restful Routes in controller specs
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
Jonathan Linowes
2009-Mar-11 13:35 UTC
[rspec-users] [rspec, rails] Restful Routes in controller specs
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-usersYou 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
David Chelimsky
2009-Mar-11 13:39 UTC
[rspec-users] [rspec, rails] Restful Routes in controller specs
On Wed, Mar 11, 2009 at 3:30 AM, Andi Schacke <memberships.andi at 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> > thanks > Andi > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Andi Schacke
2009-Mar-11 14:04 UTC
[rspec-users] [rspec, rails] Restful Routes in controller specs
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 On Mar 11, 2:39?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Wed, Mar 11, 2009 at 3:30 AM, Andi Schacke > > <memberships.a... at 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 > > > > > thanks > > Andi > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users