gpt4 book ai didi

ruby-on-rails - Ruby on Rails,测试时出现 Rspec 错误

转载 作者:行者123 更新时间:2023-11-28 20:04:08 25 4
gpt4 key购买 nike

我正在学习 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

最佳答案

您需要在规范源中require 'spec_helper'

您的 spec_helper 应该同时包含 rspec/railscapybara/rails

但是,如果您想访问响应,则需要使用 get 而不是 visit

关于ruby-on-rails - Ruby on Rails,测试时出现 Rspec 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12255432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com