Mike Perham

On Ruby, software and the Internet

Developing Rubygems with RVM and Bundler

August 3rd, 2010 · 3 Comments

It’s safe to say that RVM and Bundler have completely changed how I interact with my Ruby applications and gems. It’s pretty well understood how to use each by itself, I didn’t have a good idea how to use them in tandem until recently. Parts of this post are based on Derek Kastner’s great post on using Bundler.

When I grab the source for a random rubygem from github and want to run its tests or test drive it, I use RVM and Bundler to create a sandbox so I don’t pollute the gems used by other Ruby projects on my box:

  rvm use 1.9.2@<gemname> --create
  gem install bundler --pre
# Would love to see this cleaned up for bundler 1.0
# e.g. bundle install --from-gemspec
  cat > Gemfile <<EOM
source 'http://rubygems.org'
gemspec :path => '.'
EOM
  bundle install
  rake

The only trick here is using Bundler’s support for gemspecs to avoid the need for a separate (and redundant) Gemfile. But Andre Arko suggests that we prefer Bundler to Jeweler and I agree with him. Jeweler should check for an existing Gemfile and defer to it for dependencies when generating the gemspec:

require 'bundler'
Gem::Specification.new do |s|
  s.add_bundler_dependencies
end

This means that gems should check in their gemspec into git and jeweler (or however you are generating your gemspec) should be declared as a development dependency. Do your gems pass this simple test? Any thoughts on how to make this even simpler?

Tags: Ruby

3 responses so far ↓

  • 1 Wayne E. Seguin // Aug 3, 2010 at 8:08 pm

    Comments in the Gist explain my thoughts:

    https://gist.github.com/ed6423a598b2c0c2a0e9

    ~Wayne

  • 2 Bundler: Best way to manage your Gems « Veerasundaravel's Weblog // Sep 22, 2010 at 6:32 am

    [...] Developing Rubygems with RVM and Bundler (mikeperham.com) [...]

  • 3 Derek // Dec 29, 2010 at 9:24 am

    Hey, thanks for the shout out, just found it today! I’m also working on a modified version of jeweler that takes the best parts of jeweler (bumping versions, releasing code) but relies more on bundler’s features and does away with the Rakefile-generated gemspec. It’s a side project for now, but all I have left to do is decide on a way to modify the version in the gemfile, whether it’s via regex replace or modifying ruby s-expressions via ruby_parser. http://github.com/dkastner/bueller

Leave a Comment