簡體   English   中英

Rails教程3第7.1.3章rspec失敗測試

[英]Rails Tutorial 3 chapter 7.1.3 rspec failing tests

我花了幾個小時仔細閱讀本書和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

我遍歷了所有可以檢查出什么問題的文件。

app / views / users / new.html.erb

<% provide(:title, 'Sign Up') %>
<h1>Sign Up</h1>
<p>Find me in app/views/users/new.html.erb</p>

** app / views / users / 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 

感謝您的幫助和時間!

刪除第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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM