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.