Forum: Ruby on Rails name_url in tests

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.
Dorian M. (Guest)
on 2006-05-09 08:08
(Received via mailing list)
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'
Rob S. (Guest)
on 2006-07-22 12:36
(Received via mailing list)
On 5/8/06, Dorian M. <removed_email_address@domain.invalid> wrote:
>
>
>     test/functional/films_controller_test.rb:92:in `test_routes'
>
>
> --
> --
> I do things for love or money
> _______________________________________________
> Rails mailing list
> removed_email_address@domain.invalid
> http://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:

http://www.robsanheim.com/2006/07/22/testing-named...

- Rob
This topic is locked and can not be replied to.