views:

576

answers:

2

I just changed my Rails 2.3.8 project to load gems using Bundler, rather than the default Rails 2.3 loading mechanism. I followed the official instructions and the site runs fine in development. I use RVM for gem management, and have a specific gemset loaded for the application.

My RSpec test suite is unable to run, however. I have tried running both the entire suite and single tests using a variety of commands:

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

I have also tried running them all prefixed with bundle exec. Everything returns the same error:

/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

I'm pretty sure the problem is not related to the Inherited Resources gem - I think gems are not loaded at all at this point, and Inherited Resources just happens to be the first one needed.

The thing that's baffling me is that /activesupport-2.3.8/lib/active_support/dependencies.rb:158 requires /app/controllers/admin/base_controller during the initialization phase. It shouldn't do that, and it certaintly doesn't do it in development mode. I can comment out gem 'inherited_resources' in my Gemfile, and site still runs. It's not until I hit an action that loads a controller that use Inherited Resources I get the "uninitialized constant" error.

For clarity, here's my Gemfile and spec_helper.rb.

A: 

I realize this is an old question, but I just came across the same problem.

I had the 1.3.0 version of rspec and rspec-rails required by my application. Looking at the rspec-rails changelog, I noticed there were a few bug fixes after 1.3.0. Upgrading rspec-rails to 1.3.2 fixed everything for me.

agregoire
Thanks for mentioning this. It might help someone else, but not me. I was already on RSpec 1.3.2. I just updated and tried out my broken bundler branch again - still the same error.
Casper Fabricius
A: 

Even older question, but I had the same issue with Bundler 1.0.3, Rspec-Rails 1.3.3 & Rails 2.3.8 and was able to boil it down to remarkable_rails. Remarkable-Rails seems to load rspec/rails before the initializers are run by the environment.

After adding :require => nil to it in the Gemfile and requiring it by hand in spec_helper AFTER requiring the rails-environment the issue disappeared.

Sebastian