mardi 21 juin 2016

Rails5 NameError: undefined local variable or method

I'm working my way through the railstutorial (yet again) and I'm trying to make things work with rails 5.0.0.rc1. The problem is that the path_to_wherever variables seem to have been removed or renamed. I haven't been able to find any information on how to migrate the tests, which I assume is because rails 5 isn't out yet.

This is the error I get when running rails test (formerly rake test):

bin/rails test test/integration/users_signup_test.rb:5

E

Error:
SessionsControllerTest#test_should_get_new:
NameError: undefined local variable or method `sessions_new_url' for #<SessionsControllerTest:0x00000001d70d10>
    test/controllers/sessions_controller_test.rb:5:in `block in <class:SessionsControllerTest>'

code in test/integration/users_signup_test.rb:

require 'test_helper'

class UsersSignupTest < ActionDispatch::IntegrationTest

  test "invalid signup information" do
    get signup_path
    assert_no_difference 'User.count' do
      post users_path, user: { username:  "", email: "user@invalid", password: "foo"}
    end
    assert_template 'users/new'
    assert is_logged_in?
  end
end

Now in the earlier tests I had the same problem and I ended up just throwing hardcoded paths into the tests:
File: test/controllers/static_pages_controller_test.rb:

test "should get help" do
  get "/help"
  assert_response :success
  assert_select "title", "Projectz! Help"
end

because I couldn't figure out how to do it....
File: config/routes.rb:

Rails.application.routes.draw do

  root             'static_pages#home'
  get 'help'    => 'static_pages#help'
  get 'about'   => 'static_pages#about'
  get 'contact' => 'static_pages#contact'
  get 'signup'  => 'users#new'

  get    'login'   => 'sessions#new'
  post   'login'   => 'sessions#create'
  delete 'logout'  => 'sessions#destroy'

  resources :users

  # For details on the DSL available within this file, see http://ift.tt/GVpneB
end

Aucun commentaire:

Enregistrer un commentaire