我正在关注 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
宝石文件.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