Skip to content
This repository was archived by the owner on Nov 16, 2018. It is now read-only.

IronRuby and .NET

Jirapong edited this page Aug 13, 2010 · 21 revisions

Developing in .NET? You can use Cucumber with IronRuby. You need both IronRuby and MRI (Matz Ruby Interpreter).

(Mono users – see IronRuby and Mono)

Installing MRI

You’ll need MRI to build IronRuby. You also need MRI to install gems since IronRuby can
not install its own gems yet (although it can use them). When you have installed IronRuby you
can use gems installed into MRI from IronRuby.

Just download the latest Ruby One click installer from RubyForge and run it with the defaults.
When you open a new command prompt you should be able to run:

ruby --version

and

rake --version

If you already have MRI installed, make sure you have the latest version of RubyGems:

SET HOME=C:\tmp
gem update --system

Installing IronRuby

SVN for IronRuby is old, do refer to http://wiki.github.com/ironruby/ironruby/building for current build process

With MRI installed we can install IronRuby. At the time of this writing there is no installer
for IronRuby, so you have to download the IronRuby sources from the Subversion repository and build
it yourself.

If you don’t have Subversion installed, install the Subversion command line toolset (or TortoiseSvn
if you have command line fobia).

Get IronRuby sources

svn checkout http://ironruby.rubyforge.org/svn/trunk ironruby
cd ironruby

Note: checkout means “pull down a copy of the sources to my local machine”. It’s not the same
as checkout in TFS or Visual SourceSafe (which I truly hope you have moved past).

Build IronRuby

Open a Visual Studio command prompt and cd to where you downloaded the IronRuby sources. Build it:

rake compile

You may need the ‘pathname2’ gem installed if you see this error when running the rake:

rake aborted!
no such file to load -- pathname2

If you see this message, simply install the ‘pathname2’ gem:

gem install pathname2

When you have completed this step you should be able to run

build\debug\ir.exe

This should give you a new prompt (Interactive IronRuby shell). Just type exit
and hit enter. You have installed IronRuby!

Installing required gems

Since IronRuby doesn’t yet know how to install gems you have to install them using MRI:

gem install cucumber rspec

(Note: until Cucumber 0.1.12 is released you have to get the Cucumber code from Git and build the gem yourself).

Creating a Cucumber wrapper script for IronRuby

When Cucumber is installed, a cucumber.bat script is placed under your MRI’s bin directory.
This script will run Cucumber with MRI. We’ll make a similar one that will launch Cucumber
with IronRuby.

Create an empty file called icucumber.bat in MRI’s bin directory.
Open it in your favourite text editor (I hope you have installed something better than
Notepad, but it will do).

On my system icucumber.bat looks like this (You may have to change the path to ir.exe).

@ECHO OFF
REM This is to tell IronRuby where to find gems.
SET GEM_PATH=c:\ruby\lib\ruby\gems\1.8
@"C:\ironruby\build\debug\ir.exe" "c:\ruby\bin\cucumber" %* 

Tip: C:\ruby\… is just the path to your Ruby installation, if you’ve chosen to install it elsewhere, change that part of the script. Also C:\ironruby\… is just the path to your IronRuby installation, so again, if you’ve chosen to install it elsewhere (like C:\Languages\IronRuby), you should update the script.

Now you should be able to run Cucumber with IronRuby:

icucumber --help

Running the examples

Open a command prompt and cd to the Cucumber examples directory. If you have installed MRI to the default
location you’ll find them under C:\ruby\lib\ruby\gems\1.8\gems\cucumber-X.Y.Z\examples. (Replace X.Y.Z with the Cucumber version you installed above).

If you pulled the Cucumber code with Git, you’ll find the examples under examples.

Run the plain ruby example

cd i18n\en
icucumber features

The Code under test is pure Ruby, so it’s not that interesting in the context of IronRuby.

Run the C# example

cd cs
compile.bat
icucumber features

The code under test is C#. Now go ahead and add some Cucumber love to your own C# code!

Clone this wiki locally