我似乎未能通过6项规格测试。好消息是我因为同样的原因而失败了!所以,这些是我得到的测试结果:
1)认证登录页面 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
2)认证登录页面 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
3)认证登录页面包含有效信息 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
4)认证登录页面,包含有效信息 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
5)认证登录页面包含有效信息 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
6)认证登录页面包含有效信息 失败/错误:{visit signin_path}之前 ::的ActionView MissingTemplate: 缺少模板会话/ new,application / new with {:locale => [:en],:formats => [:html] ,:handlers => [:erb,:builder,:raw,:ruby,: jbuilder,:coffee]}。搜索范围: *“/ Users / Brawain / rails_projects / sample_app / app / views” './spec/requests/authentication_pages_spec.rb:8:in'块(3级)'
以下是相关文件。所以,我的规格:
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') }
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
it { should have_title(user.first) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
这是我的utilities.rb
include ApplicationHelper
def full_title(page_title)
base_title = "Techmasters"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
def valid_signin(user)
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
RSpec::Matchers.define :have_error_message do |message|
match do |page|
expect(page).to have_selector('div.alert.alert-error', text: message)
end
end
登录app / views / sessions / new.html.erb
页面<% 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>
会话控制器
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_to user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
end
我的用户控制器
class User < ActiveRecord::Base
attr_accessible :first, :last, :email, :password, :password_confirmation
has_secure_password
before_save { self.email = email.downcase }
before_create :create_remember_token
validates :first, :last, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[andover]+\.[edu]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
has_and_belongs_to_many :order
has_many :orders_users
def User.new_remember_token
SecureRandom.urlsafe_base64
end
def User.encrypt(token)
Digest::SHA1.hexdigest(token.to_s)
end
private
def create_remember_token
self.remember_token = User.encrypt(User.new_remember_token)
end
end
会议助手
module SessionsHelper
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
remember_token = User.encrypt(cookies[:remember_token])
@current_user ||= User.find_by(remember_token: remember_token)
end
end
标题代码
<header class="navbar navbar-fixed-top navbar-inverse">
<div class="navbar-inner">
<div class="container">
<%= link_to "sample app", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
这是注册页面
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<%= f.label :first %>
<%= f.text_field :first %>
<%= f.label :last %>
<%= f.text_field :last %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
我认为这是我能给你的所有可能的信息。我可以给你我的其他规格,但我通过了那些,所以我认为这将是愚蠢的。无论如何,你们中的任何人都知道出了什么问题吗?
编辑:Rake routes命令。
Prefix Verb URI Pattern Controller#Action
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
root GET / static_pages#home
signup GET /signup(.:format) users#new
signin GET /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
答案 0 :(得分:0)
对于那些错误,它只是说它找不到那些处理程序的视图文件,
介意我看看
的结果rake routes
命令?
我假设您没有任何其他规格要求
visit signin_path