我刚刚改变了我的Rails 2.3.8项目,使用Bundler加载gems,而不是默认的Rails 2.3加载机制。我跟着the official instructions,该网站在开发中运行良好。我使用RVM进行gem管理,并为应用程序加载了特定的gemset。
然而,我的RSpec测试套件无法运行。我尝试使用各种命令运行整个套件和单个测试:
autospec # My usual way of running tests
rake spec
spec .
spec spec/models/comment_spec.rb # Trying a single spec file in isolation
ruby spec/models/comment_spec.rb
我也试过运行它们所有前缀为bundle exec
。一切都返回相同的错误:
/Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:440:in `load_missing_constant': uninitialized constant InheritedResources::Base (NameError)
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing_not_from_s3_library'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/aws-s3-0.6.2/lib/aws/s3/extensions.rb:206:in `const_missing'
from /Users/casper/Projects/cf/darebusters/app/controllers/admin/base_controller.rb:1
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in `depend_on'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in `require_dependency'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:414:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:413:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `each'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:411:in `load_application_classes'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:197:in `process'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `send'
from /Users/casper/.rvm/gems/ruby-1.8.7-p248@darebusters/gems/rails-2.3.8/lib/initializer.rb:113:in `run'
from /Users/casper/Projects/cf/darebusters/config/environment.rb:9
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5:in `require'
from /Users/casper/Projects/cf/darebusters/spec/spec_helper.rb:5
from spec/models/comment_spec.rb:1:in `require'
from spec/models/comment_spec.rb:1
我很确定这个问题与Inherited Resources gem无关 - 我认为此时根本没有加载gems,而且Inherited Resources恰好是第一个需要的。
令我感到困惑的是/activesupport-2.3.8/lib/active_support/dependencies.rb:158
在初始化阶段需要/app/controllers/admin/base_controller
。它不应该那样做,并且肯定不会在开发模式下这样做。我可以在我的Gemfile中注释掉gem 'inherited_resources'
,网站仍在运行。直到我点击一个加载使用继承资源的控制器的操作,我才得到“未初始化的常量”错误。
为清楚起见,这是我的Gemfile and spec_helper.rb。
答案 0 :(得分:2)
即使是较老的问题,但我对Bundler 1.0.3,Rspec-Rails 1.3.3& Rails 2.3.8并且能够将其归结为非凡的行业。 Remarkable-Rails似乎在环境运行初始化程序之前加载rspec / rails。
添加后:require =>在Gemfile中没有它,并且在spec_helper中需要它在需要rails-environment之后问题就消失了。
答案 1 :(得分:1)
我意识到这是一个老问题,但我遇到了同样的问题。
我的应用程序需要1.3.0版本的rspec和rspec-rails。看看rspec-rails changelog,我发现在1.3.0之后有一些错误修复。将rspec-rails升级到1.3.2可以解决所有问题。
答案 2 :(得分:1)
为了解决这个问题,我改变了Gemfile:
gem 'rspec-rails', '~> 1.3.2', :require => 'spec/rails'
到
gem 'rspec-rails', '~> 1.3.2'
并将以下内容添加到我的规范助手
中require 'spec/rails'