Ruby on rails 迈克尔·哈特尔';s Rails教程练习8.1 Rspec故障
我是一名Rails新手,正在学习Michael Hartl最新的Rails教程。我正在运行Ruby 2.0.1和Rails 4.0 测试身份验证时,我的Rspec返回以下错误 如果我的帖子不够详细,我提前表示歉意,请让我知道是否还有其他可以帮助解决这个问题的内容 我感谢每一个人的时间 谢谢 失败:Ruby on rails 迈克尔·哈特尔';s Rails教程练习8.1 Rspec故障,ruby-on-rails,ruby,rspec,ruby-on-rails-4,railstutorial.org,Ruby On Rails,Ruby,Rspec,Ruby On Rails 4,Railstutorial.org,我是一名Rails新手,正在学习Michael Hartl最新的Rails教程。我正在运行Ruby 2.0.1和Rails 4.0 测试身份验证时,我的Rspec返回以下错误 如果我的帖子不够详细,我提前表示歉意,请让我知道是否还有其他可以帮助解决这个问题的内容 我感谢每一个人的时间 谢谢 失败: 1) Authentication with valid information Failure/Error: it { should have_title(user.name) } exp
1) Authentication with valid information
Failure/Error: it { should have_title(user.name) }
expected #has_title?("John Smith") to return true, got false
# ./spec/requests/authentication_pages_spec.rb:25:in `block (3 levels) in <top (required)>'
2) Authentication with valid information
Failure/Error: it { should have_link('Sign out', href: signout_path) }
expected #has_link?("Sign out", {:href=>"/signout"}) to return true, got false
# ./spec/requests/authentication_pages_spec.rb:27:in `block (3 levels) in <top (required)>'
3) Authentication with valid information
Failure/Error: it { should have_link('Profile', href: user_path(user), visible: false) }
expected #has_link?("Profile", {:href=>"/users/1", :visible=>false}) to return true, got false
# ./spec/requests/authentication_pages_spec.rb:26:in `block (3 levels) in <top (required)>'
会话\u controller.rb
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
visit signin_path
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
end
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user), visible: false) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
end
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>
SampleApp::Application.routes.draw do
resources :users x
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'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root to: 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
---------------------------------------------------------------------------------------
谢谢,我真的很感谢你的回答。添加点击按钮“登录”
行后,我在运行Rspec时开始收到以下错误
Failures:
1) Authentication with valid information
Failure/Error: click_button "Sign in"
ActionView::MissingTemplate:
Missing template sessions/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/Ladarris/rails_projects/sample_app/app/views"
# ./spec/requests/authentication_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
2) Authentication with valid information
Failure/Error: click_button "Sign in"
ActionView::MissingTemplate:
Missing template sessions/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/Ladarris/rails_projects/sample_app/app/views"
# ./spec/requests/authentication_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
3) Authentication with valid information
Failure/Error: click_button "Sign in"
ActionView::MissingTemplate:
Missing template sessions/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/Ladarris/rails_projects/sample_app/app/views"
# ./spec/requests/authentication_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
4) Authentication with valid information
Failure/Error: click_button "Sign in"
ActionView::MissingTemplate:
Missing template sessions/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
* "/Users/Ladarris/rails_projects/sample_app/app/views"
# ./spec/requests/authentication_pages_spec.rb:24:in `block (3 levels) in <top (required)>'
故障:
1) 使用有效信息进行身份验证
失败/错误:单击按钮“登录”
ActionView::缺少模板:
缺少模板会话/create、应用程序/create和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。搜索:
*“/Users/Ladarris/rails\u projects/sample\u app/app/views”
#./spec/requests/authentication\u pages\u spec.rb:24:in'block(3级)in'
2) 使用有效信息进行身份验证
失败/错误:单击按钮“登录”
ActionView::缺少模板:
缺少模板会话/create、应用程序/create和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。搜索:
*“/Users/Ladarris/rails\u projects/sample\u app/app/views”
#./spec/requests/authentication\u pages\u spec.rb:24:in'block(3级)in'
3) 使用有效信息进行身份验证
失败/错误:单击按钮“登录”
ActionView::缺少模板:
缺少模板会话/create、应用程序/create和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。搜索:
*“/Users/Ladarris/rails\u projects/sample\u app/app/views”
#./spec/requests/authentication\u pages\u spec.rb:24:in'block(3级)in'
4) 使用有效信息进行身份验证
失败/错误:单击按钮“登录”
ActionView::缺少模板:
缺少模板会话/create、应用程序/create和{:locale=>[:en]、:formats=>[:html]、:handlers=>[:erb、:builder、:raw、:ruby、:jbuilder、:coffee]}。搜索:
*“/Users/Ladarris/rails\u projects/sample\u app/app/views”
#./spec/requests/authentication\u pages\u spec.rb:24:in'block(3级)in'
在填写电子邮件和密码后,您还需要在“使用有效信息”示例中单击该按钮,以便提交表单并呈现下一页
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
visit signin_path
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in" # <------------------- Add this line
end
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user), visible: false) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
描述“使用有效信息”是否
let(:user){FactoryGirl.create(:user)}
在做之前
参观签名道
在“电子邮件”中填写:user.Email.upcase
在“密码”中填写:user.Password
单击按钮“登录”#我现在收到一组新的错误消息,我已在我的原始帖子后添加了详细信息。@user3104275,这些错误意味着您没有app/views/sessions/create.html.erb
。您正在调用create
操作中的redirect\u back\u或
helper,因此如果不查看该操作,就很难说出发生了什么。然而,问题似乎存在。我建议您为此问题创建一个新问题,以便其他用户也能参与进来。