InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Checking 1.8 vs 1.9 compatibility with Multiruby

Posted by Werner Schuster on Feb 08, 2008

Sections
Development
Topics
Ruby ,
Unit Testing
Tags
Testing ,
ZenTest
Developers working on Ruby libraries or applications have a new task on their hands: making sure their code works across Ruby versions. Alternative Ruby implementations are one reason, but they generally aim to work exactly like MRI. With the release of Ruby 1.9, this has changed: Ruby 1.9 has some changes that aren't compatible or at least change the behavior of some code. 

For instance, pre-1.9, Ruby's had a problem with local variables in blocks. For instance:
 a = 1
 foo.do_something {|a|
 a = 42
 }
 puts a
In Ruby 1.8, this code prints "42", because the block variable a is actually the same a of the containing scope. Ruby 1.9 fixes this to make blocks behave as expected, i.e. print "1". Of course, if a library's or application's code relied on the old behaviour, it will behave differently on Ruby 1.9.

A part of the Zentest package helps to avoid this: Multiruby. Ryan Davis, creator of Zentest, explains how to handle Ruby 1.8 and 1.9 with Multiruby:
Now that 1.9 is out, it is time to talk about multi-version testing using multiruby. multiruby is a lesser known tool in the zentest family. It automatically builds and privately installs multiple versions of ruby and multiplexes commands to all of them, allowing you to run your tests across multiple versions of ruby all at once.
Installing Zentest is simple:
gem install ZenTest 
Multiruby works as such:
  • It will download and compile Ruby versions, eg. 1.8 and 1.9
  • Then it executes it's arguments with each one of the available Ruby versions
The multiruby command simply passes all given arguments through to the Ruby binary. Running the code example from above will have this output:
VERSION = 1.8.6-p111
 42
RESULT = 0

VERSION = 1.9.0-0
 1
RESULT = 0

TOTAL RESULT = 0
 failures out of 2

Passed: 1.8.6-p111, 1.9.0-0
Failed:
As can be seen: the output in 1.8.x is "42", but in 1.9 becomes "1". (The "RESULT" here is the exit code of the Ruby interpreter).

Naturally, Multiruby will only help to expose problems if a large enough percentage of the code is covered by tests. With ever more Ruby versions, JRuby 1.0 and 1.1, IronRuby and Rubinius becoming available, a tool that simplifies testing across runtimes is quite useful.

Have you started porting or at least testing your applications or libraries with Ruby 1.9?

No comments

Watch Thread Reply

Educational Content

Jesper Boeg on Priming Kanban

In this interview, Jesper Boeg, author of the new InfoQ book – Priming Kanban, discusses the keys to using Kanban effectively, and how to get started if you are currently using other approaches.

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.