Cucumber and IronRuby: It Runs!
Ever since I read about Cucumber, a user acceptance testing tool in Ruby, I’ve wanted to be able to use it, along with IronRuby for my .Net projects. I got it working once, briefly, using the directions on the Cucumber wiki at GitHub. With an uncertain combination of IronRuby updates and Cucumber updates, it stopped working for me. Well, this evening, I decided to delve into it once again, and I am now happy to report that it works! Well, works, as in runs the C# sample provided with the Cucumber gem. I know present to you the steps I took to get it working, from end to end (I’ll assume you have some version of Visual Studio 2008 with C#):
1 – Install MSysGit
Head on over the the MSysGit page, grab the latest Git-1.6.x.y install, and run it. At the time of this writing, I’m using 22.214.171.124-preview20090408
2 – Grab the IronRuby sources
I prefer to do all my development work in C:\Development. Pop open a Git Bash console (Start > Programs > Git > Git Bash) and issue the following commands:
cd /C/Development git clone git://github.com/ironruby/ironruby.git git pull
OR, if you're behind a corporate firewall…
cd /C/Development git clone http://github.com/ironruby/ironruby.git git pull
3 – Set Up IronRuby Dev Environment
This comes straight from the dev.bat entry in the IronRuby wiki on GitHub:
We recommend you start your developing by running
C:\path\to\Merlin\Main\Languages\Ruby\Scripts\Dev.bat. This batch file sets up the path, various environment variables, and aliases, which makes it easy to do builds and run tests.
It is recommended to setup a shortcut to Dev.bat on the desktop that you can just click to quickly get the pre-configured environment. To do this, create a shortcut on the Desktop to cmd.exe (where C:\Development\ironruby is the root of your GIT repo) looking like CmdShortcut.png at http://www.ironruby.net/Support/Images. The values of the text fields should be like this:
C:\Windows\System32\cmd.exe /k "c:\Development\IronRuby\Merlin\Main\Languages\Ruby\Scripts\Dev.bat"
I highly recommend reading the rest of that wiki entry. It explains how the IronRuby sources are laid out.
I’m also made a change to Dev.bat. On line 43, after :EnvDone, the script changes the path. I’m going to prepend the path to the IronRuby interpreter, which we’ll compile in the next step. Why prepend? Well, I also have MRI in my path, and I found that the commands in C:\Ruby\bin were getting called instead of the IronRuby versions. This is what I believe was leading to all the difficulties I had in the past. So, the call to SET PATH should look something like this:
Addendum - June 14th, 2009
After some feedback on this post from Jimmy Schementi and Jim Deville of the IronRuby team, you’re going to want to set another environment variable, called GEM_BIN. We will reference this variable later, when we go to install gems for IronRuby. After the line that sets GEM_PATH, about line 16, you want to include this additional line:
Adding this will allow us to tell Ruby Gems where to put the scripts needed to run cucumber, or any other gem. I’ve chosen %MERLIN_ROOT%\Languages\Ruby\Scripts\Bin, on Jimmy’s suggestion, because it is already in the path set by Dev.bat, and IronRuby distributes a number of other wrapper scripts, such as igem, irake, and irails in this directory.
4 - Compile IronRuby
Pop open the IronRuby Development console (the shortcut you created in the previous step), and run
brbd (Build RuBy Debug).
5 – Install the Cucumber Gem
IronRuby comes with a command called igem, which runs the gem command using IronRuby, as opposed to the standard MRI. In that same development console, run:
igem install –-no-rdoc -–no-ri –-bindir %GEM_BIN% cucumber
That’s a lot to type! We could stick all these options into a .gemrc file in our home directory, but this is problematic if you have and use multiple versions of Ruby on your machine (and you most likely will). Any suggestions for accommodating the scenario of multiple Ruby versions with seperate Gem locations would be very much appreciated! Now, back to the show!
I’m choosing to include the
-–no-ri because RDoc and RI generation is slooooow, and I can’t recall the last time I looked at either.
I’m also passing the
–-bindir argument so that the wrapper scripts for the gems I install will be placed into a directory that is in my path, but will not get overwritten every time I recompile IronRuby.
This will install the gem files into
C:\Development\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ironruby\gems\1.8\gems\cucumber-xxxx, where xxxx is the latest version of Cucumber. I'm going to use cucumber-xxxx in the next step to signify the folder that cucumber gets installed into.
This will also install the
cucumber & cucumber.bat wrapper scripts into
6 – Verify that it Works
Here comes the cool part. In that same IronRuby dev console window, do the following:
cd C:\Development\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ironruby\gems\1.8\gems\cucumber-xxxx\examples\cs compile.bat cucumber features
This is the output that I got:
*** WARNING: You must "gem install win32console" (1.2.0 or higher) to get colour ed output on MRI/Windows Feature: Addition In order to avoid silly mistakes As a math idiot I want to be told the sum of two numbers unknown:0: warning: multiple values for a block parameter (2 for 1) unknown:0: warning: multiple values for a block parameter (2 for 1) Scenario Outline: Add two numbers # features/addition.feature:6 unknown:0: warning: multiple values for a block parameter (2 for 1) Given I have entered
into the calculator # features/step_definitons/calculator_steps.rb:9 unknown:0: warning: multiple values for a block parameter (2 for 1) And I have entered into the calculator # features/step_definitons/calculator_steps.rb:9 unknown:0: warning: multiple values for a block parameter (2 for 1) When I press add # features/step_definitons/calculator_steps.rb:13 unknown:0: warning: multiple values for a block parameter (2 for 1) Then the result should be
Notice that there are still some warnings. I know John Lam and the rest of the IronRuby team are working hard for to get this working for the 1.0 release, due on or about July 23rd, 2009. Most importantly, though, it functions now. Cool beans!
SUPER KIND-OF IMPORTANT NOTE!
Any time you rebuild IronRuby, the C# compiler will erase the contents of the directory
C:\Development\IronRuby\Merlin\Main\Bin\Debug. This includes the cucumber and cucumber.bat files.
The only way I know to rectify this is to igem install -–no-rdoc -–no-ri cucumber once again. Thanks to feedback from the IronRuby team, I’ve detailed a fix above. You will only have to install gems once, regardless of how often you recompile IronRuby.