Developing Rubygems with RVM and Bundler

2010-08-03

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?