【发布时间】:2016-05-25 19:52:33
【问题描述】:
我正在关注 Ruby on Rails 教程并遇到以下问题:
me@me:~/Ruby/sample_app$ bundle exec rspec spec/requests/static_pages_spec.rb
F
失败:
1) 静态页面首页应该有内容'Sample App' 失败/错误:访问'/static_pages/home'
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::StaticPages::HomePage:0x00000001e1df88>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
在 0.0006 秒内完成(加载文件需要 0.08149 秒) 1 个示例,1 个失败
失败的例子:
rspec ./spec/requests/static_pages_spec.rb:7 # 静态页面首页应该有内容'Sample App'
这是我的 Gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'rspec-rails'
end
group :assets do
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
end
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
group :test do
gem 'capybara'
end
group :prodcution do
gem 'pg'
end
我的规范/请求/static_pages_spec.rb:
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
在网上搜索建议将 config.include Capybara::DSL 放在 spec/spec_helper.rb 中。我这样做了,但没有工作。另一个建议说我需要将我的 static_pages_spec.rb 移动到规范/功能。我这样做了,但也没有用。
帮助? :D
【问题讨论】:
标签: ruby-on-rails