我花了几个小时翻阅这本书和github页面上的代码,我似乎无法找到答案。我在7.1.3章节中尝试通过以下测试。当我查看页面时,就我所知,一切正常。
user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign Up') } (10)
it { should have_selector('title', text: full_title('Sign Up')) } (11)
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: 'user.name') } (18)
it { should have_selector('title', text: 'user.name') } (19)
end
end
我已经浏览了所有可以考虑检查可能出错的文件。
应用/视图/用户/ new.html.erb
<% provide(:title, 'Sign Up') %>
<h1>Sign Up</h1>
<p>Find me in app/views/users/new.html.erb</p>
**应用/视图/用户/ show.html.erb
<% provide(:title, @user.name) %>
<h1><%= @user.name %></h1>
app / controller / users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
end
end
config / routes.rb
SampleApp::Application.routes.draw do
resources :users
match '/contact', :to => 'pages#contact'
match '/about', :to => 'pages#about'
match '/help', :to => 'pages#help'
match '/signup', :to => 'users#new'
root :to => 'pages#home'
我想我已经附上了所有相关代码,如果添加任何其他内容会让我知道。以下是我得到的实际错误。如果你能指出我在工作中抛出扳手的地方,我将非常感激。
rspec ./spec/requests/user_pages_spec.rb:10 # User pages signup page
rspec ./spec/requests/user_pages_spec.rb:11 # User pages signup page
rspec ./spec/requests/user_pages_spec.rb:18 # User pages profile page
rspec ./spec/requests/user_pages_spec.rb:19 # User pages profile page
感谢您的帮助和时间!
答案 0 :(得分:0)
删除第18行和第19行中的引号。这应该通过测试。
像这样:
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
同时寻找你的routes.rb。在rails教程中它很好
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
除非您使用名称页面创建静态页面视图。然后忘记我的routes.rb