2012-02-22 87 views
5

我正在關注這篇文章,我可以在下面的ruby文件中編寫此代碼,主頁確實有示例應用程序,但它仍然表示靜態頁面頁面應該有內容 '示例應用程序',當我運行bundle exec rspec spec/requests/static_pages_spec.rb在Rails中運行bundle exec rspec spec/requests/static_pages_spec.rb時出現錯誤

規格/請求/ static_pages_spec文件代碼:

require 'spec_helper' 

describe "Static pages" do 

    describe "Home page" do 

    it "should have the content 'Sample App'" do 
     visit '/static_pages/home' 
     page.should have_content('Sample App') 
    end 
    end 
end 

home.html.erb

<h1>Sample App</h1> 
<p> 
    This is the home page for the 
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a> 
    sample application. 
</p> 

下面是我的這個應用程序的寶石文件。請指教。謝謝你的幫助。

source 'https://rubygems.org' 

gem 'rails', '3.2.1' 
gem 'sqlite3' 

# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 
group :development do 
gem 'rspec-rails', '2.6.0' 

end 

group :test do 
gem 'webrat', '0.7.1' 
gem 'capybara', '1.0.0.beta1' 
end 

# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
    gem 'sass-rails', '3.2.3' 
    gem 'coffee-rails', '3.2.1' 

    # See https://github.com/sstephenson/execjs#readme for more supported runtimes 
    # gem 'therubyracer' 

    gem 'uglifier', '1.0.3' 
end 

gem 'jquery-rails', '2.0.0' 


group :production do 
gem 'pg', '0.12.2' 
end 

# To use ActiveModel has_secure_password 
# gem 'bcrypt-ruby', '~> 3.0.0' 

# To use Jbuilder templates for JSON 
# gem 'jbuilder' 

# Use unicorn as the web server 
# gem 'unicorn' 

# Deploy with Capistrano 
# gem 'capistrano' 

# To use debugger 
# gem 'ruby-debug19', :require => 'ruby-debug' 
+0

你可以發佈rspec運行的輸出嗎? – ScottJShea 2012-02-22 06:29:15

+0

嘗試將'page.should have_content('Sample App')'改爲'page.should have_content(「Sample App」)' – ScottJShea 2012-02-22 06:33:30

+1

您可以將'page.content'放在spec中,以檢查您獲取的內容而不是你期待的頁面。這應該讓你知道什麼是錯的。如果這不能讓我們顯示你的路線文件,問題可能在那裏。 – 2012-02-22 07:35:01

回答

6

在輸出從失敗RSpec的測試你有行FATAL: database "sample_app_test" does not exist多行錯誤Failed examples: rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content 'Ruby on Rails'以上?如果是的話下面的步驟爲我工作:

打開sample_app/config.database.yml文件在文本編輯器,並test下的Postgres的DB你使用,保存.yml文件,並重新運行數據庫更改爲實際名稱rspec測試。

0

我認爲你需要,要求在spec_helper.rb水豚manualy。這就是我通常所做的:)

0

我認爲這是與webrat的衝突。從你的寶石文件中刪除它。

#gem 'webrat', '0.7.1' 
gem 'capybara', '1.0.0.beta1' 
相關問題