Tatva-Artha

meaning of "it"

Using Bundler with rails 2.3.X

with 2 comments


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 cucumber

Enjoy!

http://www.tatvartha.com/wp-content/plugins/sociofluid/images/digg_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/reddit_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/stumbleupon_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/delicious_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/google_16.png http://www.tatvartha.com/wp-content/plugins/sociofluid/images/twitter_16.png

Related posts:

  1. Monitoring rails processes (apache, passenger, delayed_job) using god and capistrano When it comes to monitoring servers and processes in...

Related posts brought to you by Yet Another Related Posts Plugin.

Written by Sharad

June 11th, 2010 at 8:14 pm

Posted in All

2 Responses to 'Using Bundler with rails 2.3.X'

Subscribe to comments with RSS or TrackBack to 'Using Bundler with rails 2.3.X'.

  1. config/environment/test.rb should have

    require “shoulda”
    Bundler.require(:test)

    Peter DeWeese

    24 Jun 10 at 11:14 am

  2. Ah, fixed. Thanks.

    Sharad

    25 Jun 10 at 6:18 pm

Leave a Reply