使用 RSpec 出现未初始化的常量错误。不知道是什么原因造成的

发布于 2024-10-07 16:06:45 字数 4590 浏览 2 评论 0原文

我正在使用 RSpec 进行测试,当我周五下午下班时,我的测试通过了。但是当我回家并同步我的存储库时,我的笔记本电脑上的测试失败了。现在回到工作岗位,测试仍然失败。不要相信它是我的代码,因为单独运行 rspec 会返回错误,并且 spork 甚至不会启动。当我尝试启动 Spork 时,收到以下错误消息:

Using RSpec
Loading Spork.prefork block...
uninitialized constant ActionView::Template::Handlers::ERB::ENCODING_FLAG (NameError)
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.2.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:85:in `<class:ERB>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:70:in `<module:Handlers>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:28:in `<class:Template>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:27:in `<module:ActionView>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:6:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers.rb:10:in `extended'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `extend'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `<class:Template>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:8:in `<module:ActionView>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:6:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/resolver.rb:3:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/testing/resolvers.rb:1:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-rails-2.2.1/lib/rspec/rails/view_rendering.rb:1:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-rails-2.2.1/lib/rspec/rails.rb:9:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:10:in `block in <top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork.rb:23:in `prefork'
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:5:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `load'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `block (2 levels) in preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/app_framework.rb:64:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:134:in `block in preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork.rb:67:in `exec_prefork'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:120:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:25:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/runner.rb:74:in `run'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/runner.rb:9:in `run'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/bin/spork:10:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/bin/spork:19:in `load'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/bin/spork:19:in `<main>'

有人知道是什么原因造成的吗?

I'm using RSpec for testing and when I left work Friday afternoon, my tests were passing. But when I went home and synced my repository, the tests failed on my laptop. Now back at work, the tests are failing still. Don't believe its my code since running rspec by itself returns an error and spork won't even start up. When I try to start Spork, I get the following error message:

Using RSpec
Loading Spork.prefork block...
uninitialized constant ActionView::Template::Handlers::ERB::ENCODING_FLAG (NameError)
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-core-2.2.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:85:in `<class:ERB>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:70:in `<module:Handlers>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:28:in `<class:Template>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:27:in `<module:ActionView>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers/erb.rb:6:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/handlers.rb:10:in `extended'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `extend'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:99:in `<class:Template>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:8:in `<module:ActionView>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template.rb:6:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/template/resolver.rb:3:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_view/testing/resolvers.rb:1:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-rails-2.2.1/lib/rspec/rails/view_rendering.rb:1:in `<top (required)>'
<internal:lib/rubygems/custom_require>:29:in `require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rspec-rails-2.2.1/lib/rspec/rails.rb:9:in `<top (required)>'
<internal:lib/rubygems/custom_require>:33:in `require'
<internal:lib/rubygems/custom_require>:33:in `rescue in require'
<internal:lib/rubygems/custom_require>:29:in `require'
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:10:in `block in <top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork.rb:23:in `prefork'
/home/jeff/Projects/Rails/vahsfbhistory/spec/spec_helper.rb:5:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `load'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:138:in `block (2 levels) in preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/app_framework.rb:64:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:134:in `block in preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork.rb:67:in `exec_prefork'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/test_framework.rb:120:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:25:in `preload'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/runner.rb:74:in `run'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/lib/spork/runner.rb:9:in `run'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/spork-0.8.4/bin/spork:10:in `<top (required)>'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/bin/spork:19:in `load'
/home/jeff/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/bin/spork:19:in `<main>'

Anyone know what could be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半城柳色半声笛 2024-10-14 16:06:45

我遇到了这个问题。在spec_helper.rb中尝试将:替换

require "rails"

require "rails/all"

在我的情况下有效。

I ran into this problem. In the spec_helper.rb try replacing:

require "rails"

with

require "rails/all"

Worked in my situation.

梦晓ヶ微光ヅ倾城 2024-10-14 16:06:45

您需要初始化环境,将此行添加到 spec_helper.rb 中:

require File.expand_path("../../config/environment", __FILE__)

You need to initialize environment, add this line to spec_helper.rb:

require File.expand_path("../../config/environment", __FILE__)
一百个冬季 2024-10-14 16:06:45

如果您尝试在非 Rails 项目中使用 rspec-rails,则可能会遇到此问题。在这种情况下,使用 require "rails/all" 不是一个选项,因为它需要 ActiveRecord 的东西,让您留下:

ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' find.< /code>

相反,您可以通过以下方式解决此问题:

require "action_controller/railtie"

You may encounter this issue if you're trying to use rspec-rails in a non-rails project. In that case using require "rails/all" is not an option because it'd require ActiveRecord stuff leaving you with:

ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found.

Instead you can fix this issue with:

require "action_controller/railtie"

開玄 2024-10-14 16:06:45

如果它不是 Rails 应用,并且您不想包含所有 Rails,请将其添加到您的 spec_helper.rb 中:

require 'action_view'

If it's not a Rails app and you don't want to include all of Rails, add this to your spec_helper.rb:

require 'action_view'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文