I’m a Ruby monogamist. I use the Ruby that comes with Leopard (
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]). Oh sure I’ve cheated on my Ruby a couple of times. It was just sex, I didn’t fall in love, I promise.
My machine has had various versions of jRuby, Rubinius and MacRuby installed at various times, but I don’t think it’s ever had two working copies of Ruby MRI (Matz Ruby Implementation) at a time.
Ok, that’s a lie. On Christmas Day 2007, Matz released Ruby 1.9. Yes I was a deviant. I installed it. But I didn’t inhale.
ruby19 sat on my filesystem outside the $PATH. It was a trophy not a tool.
My Ruby monogamy was working out perfectly for me, whilst I collected futurist and novelty Ruby implementations as a passive hobby, until yesterday when I saw the above tweet.
That’s a bit of a bugger. I mean, why was he playing with Ruby 1.9.1 anyway?
Or perhaps having multiple version of Ruby on one computer isn’t some illicit activity. Everyone else is doing it, Your Honour.
I still didn’t care for having multiple ruby versions lying around in my path; but I had to fix rubigen. I just wanted a way to fix bugs against ruby 1.9+ and move on with my life. I didn’t want to have to do any manual work in order to set this up. Surely someone else has solved this problem already?
Yes. Ryan Davis did solve this problem already. You can follow his instructions and get most of the answers I needed. Except as of today, multiruby wasn’t pulling down my nemesis ruby 1.9.1 prerelease versions, just the latest 1.9.0 version. (update: 1.9.1 is out; installation instructions below are updated)
Also, I couldn’t figure out how to setup rubygems and I couldn’t figure out how install all the fun gems that my code needed. Ryan fixed me up with this answer too.
MultiRuby is really nice in that it installs all the version of ruby into a safe place (
~/.multiruby/) and has nice ways to add and remove versions of ruby that you want to test against. To run the tests for rubigen I ran the following code. It takes about 30 minutes from scratch.
sudo gem install ZenTest multiruby -e "p 1+1" multiruby_setup mri:svn:tag:v1_8_6_114 multiruby_setup mri:svn:tag:v1_9_1_0 multiruby_setup update:rubygems multiruby -S gem install --no-ri --no-rdoc --development test-unit rspec mocha rails
To get the full list of available ruby tagged releases, ask the SVN repo:
svn list http://svn.ruby-lang.org/repos/ruby/tags
Sometimes I got time out errors on the gem installs
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError) timed out (http://gems.rubyforge.org/gems/rails-2.2.2.gem)
The next section helps fix this if it occurs for you.
Sake tasks to help with multiruby
multiruby_setup comes with some useful helpers, and hoe generates a helpful ‘rake multi’ runner for test/unit tests of hoe gems, I wanted more helpers. These have been compiled as sake tasks in http://github.com/drnic/sake-tasks.
To install them from scratch (initial blog post):
sudo gem install sake cd /tmp git clone git://github.com/drnic/sake-tasks.git cd sake-tasks rake install:all
You can toss away the repo after installing the sake tasks.
Installing gems into multiruby
Each version of ruby has its own rubygems cache. To install a gem into each ruby version:
sake multiruby:gems:install GEM=gemname sake multiruby:gems:install GEMS=gem1,gem2
Want to see what gems were installed for each version of ruby?
multiruby -S gem list
If you use hoe, and your tests are traditional
test/unit tests, then hoe comes with a very helpful
rake multi task.
For everyone else, use the following sake tasks:
sake multiruby # Runs any tests or specs in current project against multiruby sake multiruby:spec # Runs specs in current project against multiruby sake multiruby:test # Runs tests in current project against multiruby
Miscellaneous MultiRuby management
When I was fixing rubigen, I had some failing tests against 1.9.0-5 but not against 1.9.1, so I decided I hated 1.9.0 and stopped running tests against it. You can stop supporting a version of ruby with:
Not sure what versions of ruby you’re supporting?
Theoretically you could try something like (after installing cucumber gem into multiruby):
multiruby -S cucumber features multiruby -S cucumber --format progress features
My scenarios are failing at the moment. All of them. And the log/stdout files are overwriting each other in the tmp folder. To isolate it down to one scenario you’d try something like:
multiruby -S cucumber features/executable_generator.feature:7
You can now easily isolate and run a specific cucumber scenario against a specific ruby version by copy+pasting from the output of the above line. For example:
~/.multiruby/install/v1_8_6_114/bin/ruby -S cucumber features/executable_generator.feature:7
Perhaps this is too much information. I’m still getting cucumber + multiruby working together, so I’ll add new ideas to the bottom of this post as I figure them out.
Running rake tasks
I’ve been poking around a bunch of other people’s gems seeing how many gems current pass against ruby 1.9.1 (answer: not many). When I came across nokogiri, I found that I needed to trigger the build steps of the C code first before running the tests. The simplest way to do this was via its own rake tasks.
multiruby -S rake clean test
Here we are calling the ‘clean’ task first, so that the C code is rebuilt from scratch for each new ruby version. BTW, there are 6 failing tests for v1_9_1_preview2.
- Validate and Save your Ruby in TextMate – with secret Rubinus superpowers In some TextMate bundles, if you save a file it...
- Hacking someone’s gem with github and gemcutter Ever used a rubygem, found a bug, and just...
- hash bang cucumber I don’t know if this is a good idea or...
- Cucumber: building a better World (object) How to write helper libraries for your Cucumber step definitions...
- newgem 1.0.0 all thanks to Cucumber The New Gem Generator (newgem) was exciting, moderately revolutionary, and...