2014-05-21 108 views
0

我是Ruby on Rails的新手。目前使用特立獨行的10.9.3,Rails 4.我嘗試運行rspec命令時出現以下錯誤。Michael Hartl的rails教程第3章,rspec中的錯誤

這裏是錯誤,我得到:

rspec ./spec/controllers/pages_controller_spec.rb:35 # PagesController GET 'about' should have the right title 
rspec ./spec/controllers/pages_controller_spec.rb:24 # PagesController GET 'contact' should have the right title 
rspec ./spec/controllers/pages_controller_spec.rb:11 # PagesController GET 'home' should have the right title 

我的Gemfile包括:

group :development, :test do 
    gem 'rspec-rails', '2.14.2' 
end 

group :test do 
    gem 'rspec', '2.14.1' 
    gem 'spork', '0.9.0.rc' 
end 

也是我pages_controller_spec.rb

require 'spec_helper' 

describe PagesController do 
    render_views 

    describe "GET 'home'" do 
    it "returns http success" do 
     get 'home' 
     response.should be_success 
    end 
    it "should have the right title" do 
     get 'home' 
     response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Home") 
    end 
    end 

    describe "GET 'contact'" do 
    it "returns http success" do 
     get 'contact' 
     response.should be_success 
    end 


    it "should have the right title" do 
     get 'contact' 
     response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | Contact") 
    end 
    end 
    describe "GET 'about'" do 
    it "returns http success" do 
     get 'about' 
     response.should be_success 
    end 

    it "should have the right title" do 
     get 'about' 
     response.should have_selector("title", :content => "Ruby on Rails Tutorial Sample App | About") 
    end 
    end 
end 
從下面的評論

控制器代碼:

class PagesController < ApplicationController 
    def home 
    end 

    def contact 
    end 

    def about 
    end 
end 
+0

邁克爾的教程是最有效的:)無論如何..我發現非常有用的一件事是'gem launchy'。獲取它,你可以在'visit'後面調用'save_and_open_page'來檢查頁面的外觀。 – pawel7318

+0

實際控制代碼如下:類PagesController

+0

\t \t \t Ruby on Rails的教程樣本應用軟件|約 \t \t \t \t

關於 \t \t

\t \t \t這是主頁 Ruby on Rails的教程示例應用程序。 \t \t

\t –

回答

0

您是否嘗試過檢查的文檔: https://relishapp.com/rspec

+0

我試過/但仍然得到相同的錯誤 –

+0

我讀了文檔,並運行gem install rspec-rails,安裝了bundle安裝gem並遵循方向,但仍然無法正常工作。 –

0

是那麼簡單的小寫字母「A」大約VS關於?

您的測試正在尋找字符串「Ruby on Rails教程示例應用程序|關於」,代碼正在生成「Ruby on Rails教程示例應用程序|關於」。據我所知,rspec是區分大小寫的。

我看到的另一件事是必須設置:對於測試標題是可見的。

+0

修正了這一點,我仍然得到以下錯誤的家庭,聯繫和約。 rspec ./spec/controllers/pages_controller_spec.rb:11#PagesController GET'home'應該有正確的標題 –

+0

你修好了哪個?案例或:visob – rjenkins

+0

我在內容中修復了區分大小寫的字符串。我不明白我應該怎麼做:可見=錯誤的測試標題。 –

相關問題