【发布时间】:2012-09-04 00:35:27
【问题描述】:
我正在学习 Michael Hartl 的教程。我尝试了第一个使用 Rspec 测试应用程序的测试示例,当我执行此命令时 "bundle exec rspec spec\requests\static_pages_spec.rb" 我收到此错误。
F
Failures:
1) Home page should have the content 'Sample App'
Failure/Error: visit '/static_pages/home'
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x39e1510 @example=nil>
# ./spec/requests/static_pages_spec.rb:4:in `block (2 levels) in <top (required)>'
Finished in 0.001 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/requests/static_pages_spec.rb:3 # Home page should have the content 'Sample App'
static_pages_spec.rb
describe "Home page" do
it "should have the content 'Sample App'" do
visit '/static_pages/home'
page.should have_content('Sample App')
end
end
Gemfile.rb
source 'https://rubygems.org'
gem 'rails', '3.2.1'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.10.0'
end
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails'
group :test do
gem 'capybara', '1.1.2'
end
group :production do
gem 'pg', '0.12.2'
end
【问题讨论】:
-
@ronalchn 查看整个错误消息。
-
问题不在于页面内容。无法识别“访问”。 @Dave - 要访问工作,您需要水豚并且已安装。不知道为什么这种情况还在发生
-
@Dave - 谢谢。我完整阅读了它,它说如果文件在 spec/requests 中,默认情况下会自动包含 capybara DSL,所以由于我的 static_pages_spec.rb 在 spec/requests 中,所以它应该不是问题。请指教。
-
查看此讨论:github.com/rspec/rspec-rails/issues/360 可能是相关的,但取决于 spec_helper.rb 中的内容。
标签: ruby-on-rails testing rspec