【发布时间】:2012-05-15 17:50:12
【问题描述】:
我在 http://ruby.railstutorial.org/chapters/static-pages 关注 Ruby on Rails 教程并遇到以下错误
StaticPages Home page should have the content 'Sample App'
Failure/Error: page.should have_content('Sample App')
Capybara::ElementNotFound:
Unable to find xpath "/html"
# (eval):2:in `text'
# ./spec/requests/static_pages_spec.rb:7:in `(root)'
我的Gem文件如下
source 'http://rubygems.org'
gem 'rails', '3.0.10'
gem 'jruby-openssl'
gem 'activerecord-jdbcsqlite3-adapter'
group :development, :test do
gem 'webrat'
gem 'rspec-rails', ">= 2.10.0"
gem 'capybara', ">= 1.1.2"
end
如何摆脱这个错误并通过 rspec? 源文件
require 'spec_helper'
describe "StaticPages" do
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
# puts page.html
page.should have_content('Sample App')
end
end
end
【问题讨论】:
-
stackoverflow.com/questions/11382415/… 可能重复 请检查此规范是否在规范/控制器或规范/请求中
标签: ruby-on-rails ruby rspec capybara gemfile