Hi there, I posted earlier asking about testing named routes in functional tests, but got no response, so I''m making my question less specific. It seems from the docs that it''s possible to to test named routes in cases such as: asserts_redirect_to name_url(:param => "whatever") but I haven''t seen any mention of it being used with any other tests and I keep getting an error when I try and use it in assert_recognizes (see below). Is there anything in particular I have to do to get the _url functionality imported into my tests? I''m using rails 1.1.2 thanks for any pointers in the dark-arts of URL rewriting tests. dorian Test: # named routes opts = { :action => "dotest", :test => "test1" } assert_recognizes opts, taste_url(:action => "dotest", :test => "test1") Error ( I have a route named ''taste''): test_routes(FilmsControllerTest): NoMethodError: You have a nil object when you didn''t expect it! The error occured while evaluating nil.rewrite /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:461:in `url_for'' generated/routing/named_routes/taste.rb:2:in `taste_url'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/test_process.rb:431:in `send'' /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/test_process.rb:431:in `method_missing'' test/functional/films_controller_test.rb:92:in `test_routes'' -- -- I do things for love or money
On 5/8/06, Dorian Mcfarland <loaf@isness.org> wrote:> Hi there, > I posted earlier asking about testing named routes in functional tests, but got no response, so I''m making my question less specific. > > It seems from the docs that it''s possible to to test named routes in cases such as: > asserts_redirect_to name_url(:param => "whatever") > > but I haven''t seen any mention of it being used with any other tests and I keep getting an error when I try and use it in assert_recognizes (see below). > > Is there anything in particular I have to do to get the _url functionality imported into my tests? > I''m using rails 1.1.2 > > thanks for any pointers in the dark-arts of URL rewriting tests. > > dorian > > > Test: > > # named routes > opts = { :action => "dotest", :test => "test1" } > assert_recognizes opts, taste_url(:action => "dotest", :test => "test1") > > > Error ( I have a route named ''taste''): > > test_routes(FilmsControllerTest): > NoMethodError: You have a nil object when you didn''t expect it! > The error occured while evaluating nil.rewrite > /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:461:in `url_for'' > generated/routing/named_routes/taste.rb:2:in `taste_url'' > /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/test_process.rb:431:in `send'' > /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/test_process.rb:431:in `method_missing'' > test/functional/films_controller_test.rb:92:in `test_routes'' > > > -- > -- > I do things for love or money > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails >Hi Dorian, I realize this is a late reply, but I ran into the same issue with testing named routes. This might help you: robsanheim.com/2006/07/22/testing-named-routes-or-url_for-in-functional-test - Rob