In integration tests, you can test the response of the server given a url_for_options hash, like so: get(:action, :param1 => "one", :param2 => "two", ...) assert_response :success However, this doesn''t work with a named route. # routes.rb map.thing_download "things/:id/download" {:controller => :things, :action => :download} # things_controller_test.rb: get(:download, :id => @thing.id) #=> ActionController::RoutingError, no route matches {:controller => :things, :action => :download, :id => 12} get(thing_download_path(@thing)) #=> ActionController::RoutingError, no route matches {:controller => :things, :action => "/things/12/ download"} Is there a way to get a response from a named route in functional tests? For the time being I''ve resorted to misusing integration tests for this purpose, because inheriting from ActionController::IntegrationTest gives you a get() function that takes a string, so I can do get(thing_download_path(@thing)) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Feb-04 15:12 UTC
Re: Testing response for named routes in integration tests
Adam Stegman wrote:> In integration tests, you can test the response of the server given a > url_for_options hash, like so: > get(:action, :param1 => "one", :param2 => "two", ...) > assert_response :success > > However, this doesn''t work with a named route. > # routes.rb > map.thing_download "things/:id/download" {:controller > => :things, :action => :download} > > # things_controller_test.rb: > get(:download, :id => @thing.id) #=> ActionController::RoutingError, > no route matches {:controller => :things, :action => :download, :id => > 12} > get(thing_download_path(@thing)) #=> ActionController::RoutingError, > no route matches {:controller => :things, :action => "/things/12/ > download"} > > Is there a way to get a response from a named route in functional > tests?Are you looking for assert_recognizes ? More to the point, should you care? Routing is UI-facing stuff, so (even more than elsewhere) you should be testing behavior, not URL options.> For the time being I''ve resorted to misusing integration tests > for this purpose, because inheriting from > ActionController::IntegrationTest gives you a get() function that > takes a string, so I can do > get(thing_download_path(@thing))Don''t bother with integration tests. Use Cucumber. (Also consider RSpec -- it''s a lot nicer than Test::Unit.) Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Adam Stegman
2010-Feb-04 17:14 UTC
Re: Testing response for named routes in integration tests
On Feb 4, 9:12 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Are you looking for assert_recognizes ? > > More to the point, should you care? Routing is UI-facing stuff, so > (even more than elsewhere) you should be testing behavior, not URL > options.I''m not testing the URL, I''m testing the behavior of the application when the user hits that URL, under different conditions. Under certain conditions it should be 403 Forbidden, while under others it''s 200 OK.> Don''t bother with integration tests. Use Cucumber. > > (Also consider RSpec -- it''s a lot nicer than Test::Unit.)I''ll look into those, thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Feb-04 17:33 UTC
Re: Testing response for named routes in integration tests
Adam Stegman wrote:> On Feb 4, 9:12�am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Are you looking for assert_recognizes ? >> >> More to the point, should you care? �Routing is UI-facing stuff, so >> (even more than elsewhere) you should be testing behavior, not URL >> options. > I''m not testing the URL, I''m testing the behavior of the application > when the user hits that URL, under different conditions. Under certain > conditions it should be 403 Forbidden, while under others it''s 200 OK.Right -- so you don''t need to worry about the actual path or params. You just need to test the response. I know how to do that in Cucumber, but that uses Webrat''s visit method. I''m not sure about integration tests.> >> Don''t bother with integration tests. �Use Cucumber. >> >> (Also consider RSpec -- it''s a lot nicer than Test::Unit.) > I''ll look into those, thanks.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.