Using Bundler with rails 2.3.X

Bundler is optional for rails 2.3.X. However, it is not a bad idea to upgrade to bundler for several reasons:
- It is stable now and will solve your gem dependency conflicts better than rubygems require.
- You will be better prepared to migrate to rails3 when you are ready.
Instructions for using bundler with rails 2.3 will get you off to a good start. We use shoulda and mocha for our test suite. If you do too, you may run into an issue that Yehuda rightly blogged about here.
To fix this, here is what you need to do:
In config/boot.rb, replace:
def load_gems @bundler_loaded ||= Bundler.require :default, Rails.env end
with:
def load_gems @bundler_loaded ||= begin result = Bundler.require(:default) Bundler.require(Rails.env) unless Rails.env.test? result end end
And in your config/environments/test.rb, add following at the end:
require "shoulda" Bundler.require(:test)
As Yehuda explains, Mocha adds a few features depending on weather shoulda is loaded or not. The trick is to ensure that shoulda is loaded and is available before mocha is loaded.
Besides, if you are using mocha version 0.9.8, and have a ‘require “mocha”‘ line at the bottom of your test/test_helper.rb (as required by mocha/README), you can probably remove that here. Bundler takes care of it properly.
Again, don’t forget that non-rails commands must be executed with bundle exec:
$ bundle exec cucumberEnjoy!
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.






config/environment/test.rb should have
require “shoulda”
Bundler.require(:test)
Peter DeWeese
24 Jun 10 at 11:14 am
Ah, fixed. Thanks.
Sharad
25 Jun 10 at 6:18 pm
Thanks very much for this post. I’m in the process of updating an ancient (by web standards) Rails 2.3.5 app to use Bundler for development and deployment and got bit by this. You saved me a lot of debugging.
John Wilger
16 Apr 11 at 11:09 pm