Ruby on rails Rspec测试验证页面无法';不及格

Ruby on rails Rspec测试验证页面无法';不及格,ruby-on-rails,rspec,Ruby On Rails,Rspec,我将在第8章中介绍ROR教程。我一直在测试身份验证页面。这本书我已经查了三遍,没有发现任何问题。任何人请看一看,您的帮助将不胜感激 Failures: 1) AuthenticationPages signin with valid information Failure/Error: fill_in "Password", with: user.Password NoMethodError: undefined method `Password' fo

我将在第8章中介绍ROR教程。我一直在测试身份验证页面。这本书我已经查了三遍,没有发现任何问题。任何人请看一看,您的帮助将不胜感激

Failures:

  1) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d55ed60>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  2) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d668d50>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  3) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4ba5ed08>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

  4) AuthenticationPages signin with valid information 
     Failure/Error: fill_in "Password", with: user.Password
     NoMethodError:
       undefined method `Password' for #<User:0x007fee4d68b008>
     # ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'

Finished in 0.72208 seconds
44 examples, 4 failures

Failed examples:

rspec ./spec/requests/authentication_pages_spec.rb:30 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:31 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:32 # AuthenticationPages signin with valid information 
rspec ./spec/requests/authentication_pages_spec.rb:33 # AuthenticationPages signin with valid information 
会话\u controller.rb文件:

  class SessionsController < ApplicationController
    def new
    end
def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
    else
        flash.now[:error]= 'Invalid email/password combination' # Not quite right!
        render 'new'
    end
end
    def destroy
    end
end
我认为A开头是对的,看起来应该是小写。我还看了一眼


它也是小写的。根据David Flanagan,Yukhiro Matsumoto的Ruby编程语言书,请确保我也检查了Ruby是一种区分大小写的语言。

谢谢!它是小写的hehe@Snailwalker这可能是因为您缺少sample_app/app/views文件夹(可能是sample_app/app/views/sessions/new.html.erb模板),或者您可能需要在控制器中添加渲染方法调用。很抱歉,我没有您的代码,但我希望此链接将有助于进一步:
  class SessionsController < ApplicationController
    def new
    end
def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
    else
        flash.now[:error]= 'Invalid email/password combination' # Not quite right!
        render 'new'
    end
end
    def destroy
    end
end
SampleApp::Application.routes.draw do
  resources :users
  resources :sessions, only: [:new, :create, :destroy]
  root to: 'static_pages#home'
  match '/signup',  to: 'users#new',            via: 'get'
  match '/signin',  to: 'sessions#new',         via: 'get'
  match '/signout', to: 'sessions#destroy',     via: 'delete'
  match '/help',    to: 'static_pages#help',    via: 'get'
  match '/about',   to: 'static_pages#about',   via: 'get'
  match '/contact', to: 'static_pages#contact', via: 'get'
end
describe "with valid information" do
      let(:user) { FactoryGirl.create(:user) }
      before do
        fill_in "Email",    with: user.email.upcase
        fill_in "Password", with: user.password
        click_button "Sign in"
      end