[英]Getting error while running bundle exec rspec spec/requests/static_pages_spec.rb in Rails
I am following this article where I can written this code in this ruby file below and home page does have sample app, but it still says static pages home page should have content 'Sample App' when I run bundle exec rspec spec/requests/static_pages_spec.rb
我正在关注本文,我可以在下面的此ruby文件中编写此代码,并且首页确实具有示例应用程序,但是当我运行
bundle exec rspec spec/requests/static_pages_spec.rb
时,仍然说静态页面首页应具有内容“示例应用程序” bundle exec rspec spec/requests/static_pages_spec.rb
spec/requests/static_pages_spec file code: spec / requests / 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 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>
Below is my gem file for this app. 以下是此应用程序的我的gem文件。 please advise.
请指教。 thanks for your help.
谢谢你的帮助。
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'
In the output from your failed rspec test do you have the line FATAL: database "sample_app_test" does not exist
many lines above the error Failed examples: rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page should have the content 'Ruby on Rails'
? 在失败的rspec测试的输出中,是否存在
FATAL: database "sample_app_test" does not exist
行FATAL: database "sample_app_test" does not exist
在错误上方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'
? If so the following steps worked for me: 如果是这样,以下步骤对我有用:
Open the sample_app/config.database.yml
file in a text editor, and under test
, change the database to the actual name of the postgres db you using, save the .yml file, and re-run the rspec test. 在文本编辑器中打开
sample_app/config.database.yml
文件,在test
下,将数据库更改为您使用的postgres db的实际名称,保存.yml文件,然后重新运行rspec测试。
I think this is a conflict with webrat. 我认为这与webrat有冲突。 Remove it from you gem file.
从您的gem文件中删除它。
#gem 'webrat', '0.7.1'
gem 'capybara', '1.0.0.beta1'
I think that you need to require capybara manualy in the spec_helper.rb
. 我认为您需要在
spec_helper.rb
要求水豚spec_helper.rb
。 That's what I normally do :) 那就是我通常做的:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.