This blog has been archived. Our writing has moved to makandra cards.
The blog of , a Ruby on Rails development team

How to use multiple versions of Cucumber in parallel

When you have multiple Rails projects running different versions of Cucumber, you have seen this error:

0.6.4 is not a class/module (TypeError)

Or maybe you had fun with this one:

can't activate cucumber (= 0.4.0, runtime) for [], already activated cucumber-0.6.4 for [] (Gem::LoadError)

It requires some tweaks to get multiple versions of Cucumber to play nice with each other. Also since there are three distinct ways to invoke Cucumber in a Rails project, you will need a slightly different hack for each of them.

The first way to invoke Cucumber is by calling rake cucumber. To make rake aware of the correct version, add the following line to the top of lib/tasks/cucumber.rake, replacing 0.4.0 with the desired Cucumber release:

gem 'cucumber', '=0.4.0' if Gem.available?('cucumber')

Now that rake does our bidding, we can move on. When running invididual features RubyMine uses script/cucumber rather than rake, so we will need to fix that as well. Add the following to the top of script/cucumber, right below the shebang:

require 'rubygems'
gem 'cucumber', '=0.4.0' if Gem.available?('cucumber')

Finally, some people (me!) like to run features using the cucumber executable, which uses the latest Cucumber by default. These people can either switch to rake or script/cucumber, which we already fixed. Or, if you absolutely, positively need to continue using the cucumber executable, you can request a specific Cucumber version via command line parameter:

cucumber _0.4.0_ features/articles.feature

These are tweaks that have worked for us. There are other options that involve freezing Cucumber or using the Ruby Version Manager, but we like the leightweightness of our approach.

Did you find this article helpful? Let us know in the comments.

Growing Rails Applications in Practice
Check out our e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Recent posts

Our address:
makandra GmbH
Werner-von-Siemens-Str. 6
86159 Augsburg
Germany
Contact us:
+49 821 58866 180
info@makandra.de
Commercial register court:
Augsburg Municipal Court
Register number:
HRB 24202
Sales tax identification number:
DE243555898
Chief executive officers:
Henning Koch
Thomas Eisenbarth