Rails Tutorial Chapter 8 - undefined local variable or method `signin_path'

谁都会走 提交于 2019-12-12 22:27:05

问题


I'm getting the following rSpec failed tests error.

What did I do wrong?

Many thanks..

1) Authentication signin page Failure/Error: before { visit signin_path } NameError: undefined local variable or method signin_path' for # # ./spec/requests/authentication_pages_spec.rb:8:inblock (3 levels) in '

2) Authentication signin page Failure/Error: before { visit signin_path } NameError: undefined local variable or method signin_path' for # # ./spec/requests/authentication_pages_spec.rb:8:inblock (3 levels) in '

session_controller.rb:

class SessionsController < ApplicationController 
    def 
      new 
    end 

    def 
      create 
    end

    def 
      destroy 
    end 
  end

routes.rb:

SampleApp::Application.routes.draw do 
resources :users 
resources :sessions, only: [:new, :create, :destroy]

root to: 'static_pages#home'

match '/signup', to: 'users#new' 
match '/signin', to: 'sessions#new' 
match '/signout', to: 'sessions#destroy', via: :delete

authentication_pages_spec.rb:

require 'spec_helper'

describe "Authentication" do

subject { page }

describe "signin page" do before { visit signin_path }

it { should have_selector('h1',    text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end 

end


回答1:


I had this same issue and restarting guard/spork after I created my routes solved the problem




回答2:


Did you add the signin route to routes.rb and not restart spork (assuming you're using it) before running your tests?




回答3:


Can you run rake routes from your console and show the output



来源:https://stackoverflow.com/questions/10443105/rails-tutorial-chapter-8-undefined-local-variable-or-method-signin-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!