Search code examples
ruby-on-railsroutesfunctional-testing

Functional tests not recognising any routes


I'm trying to write a very basic functional test for one of my controllers, but the problem is that it's not recognising any of my routes. They all work in the app via HTTP and can be seen in rake routes.

In fact I even added

puts ActionController::Routing::Routes.inspect

and it put out all my routes before the error.

Here's the test:

require 'test_helper'

class UsersControllerTest < ActionController::TestCase
  test "should get signup" do
    get :new
    assert_response :success
    assert_not_nil assigns(:users)
  end
end

The error:

1) Error:
test_should_get_signup(UsersControllerTest):
ActionController::RoutingError: No route matches {:controller=>"users", :action=>"new"}
/test/functional/users_controller_test.rb:5:in `test_should_get_signup'

1 tests, 0 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/Users/projectzebra/.rvm/rubies/ruby-1.8.7...]

(See full trace by running task with --trace)

Rake routes:

               POST   /users(.:format)                       {:controller=>"users", :action=>"create"}
new_user_en_gb GET    /users/new(.:format)                   {:controller=>"users", :action=>"new"}

Solution

  • Try adding a functional test for the route itself, see if that passes, and go from there.

    Something like:

    test "should route to new user" do
      assert_routing '/users/new', { :controller => "users", :action => "new" }
    end