jeudi 27 octobre 2016

Rails4 - Testing - URLGenerationError: No route matches

I've read a lot of other questions here in SO but none could solve my issue (they all appeared to be parameters related). I hope someone can help me.

Executing my controller's test I get this message:

ActionController::UrlGenerationError: No route matches 
    {:action=>"/login", :controller=>"sessions"}
test/controllers/sessions_controller_test.rb:6:in `block in 
    <class:SessionsControllerTest>'

My rake routes looks like this:

Prefix Verb   URI Pattern       Controller#Action
login  GET    /login(.:format)  sessions#new
       POST   /login(.:format)  sessions#create
logout DELETE /logout(.:format) sessions#destroy

My test itself is this one:

test "should get new" do
    puts 'debug: ' + login_path
    get login_path
    assert_response :success
end

The puts debug line prints: debug: /login

When I go to localhost:3000/login in my web browser it loads the page correctly and debug info sais that it used:

controller: sessions
action: new

Any idea why the test is not being correctly redirected to the new action and instead is looking for an inexistent action /login? Thanks!

Aucun commentaire:

Enregistrer un commentaire