Friday, July 16, 2010

IronRuby: 0 to Cucumber in 15 minutes

Screen shot 2010-07-14 at 8.50.18 PM

Once again, a 140 character (or less) “outburst” gets me in trouble with a follower and I end up with a blog post. This one is one I probably should  have written a while back. I’ve enjoyed working with IronRuby the last few months, so this little intro is long overdue.

First things first, you’ll need to install IronRuby. Head off to the download page, and click on your msi of choice and let the installer do its thing.

Since my goal here was to get cucumber ready to roll against some .Net assemblies, you’ll need to install a few gems. IronRuby comes with Ruby Gems already installed, so thankfully to install the ones you need you just need to type ‘igem install’ a few times.

Screen shot 2010-07-14 at 8.49.47 PM“Wait, what? igem? WTF?” Yeah, that’s one of the IronRuby-isms, putting an i on the front of a couple of commands. If you’ve done a bit of Ruby, you’ll have a little muscle memory to retrain, but it’s a small hurdle. (You’ll also type ‘ir’ instead of ‘ruby’ to run a script and ‘iirb’ instead of ‘irb’ to get to irb.)

So, on with our gem installing…

igem install rake

First install is rake. I’m not going to use it right away on the cucumber running, but I’ll use it at some point, I always do.

igem install albacore

Like rake, I’m not going to use this one right away, but I’ve found it to be the one must have gem if you’re using rake with your .Net builds and test runners. It just makes you life that much easier.

igem install rspec

I’m not starting out writing rspec in this example, but cucumber is going to use its matchers.

igem install cucumber –-version “=0.6.4”

This is the one we’re after for this example. Be sure to add that version command on there because IronRuby isn’t quite ready for the latest version of Cucumber. But, 0.6.4 is going to get the job done for us.

igem install iron-term-ansicolor

The first time you run cucumber, it’s going to advise you to install this gem to get color coding in the terminal window. Go ahead and do it now, and you skip that warning. (Or don’t, and check the message for yourself. ;) )

Now all you need is some features, some step definitions, and a dll to write it all against. As luck would have it, I have just that written up in a code sample that I just used at Codestock a couple weeks ago. (And also coming soon to an Ohio user group meeting near you…) Here’s the root of that project: http://github.com/timwingfield/TestingSeaPound

The features directory there is where you’ll find my cucumber samples and the dll they are running against. Download it and give it a shot. Once you get it downloaded, open the command prompt in whatever directory contains the features directory (not the actual features directory) and type:

cucumber features

Happy IronRubying!

3 comments:

Unknown said...

All of these steps work on my workstation except the actual cucumber install. I get the following error on both IronRuby 1.0 and 1.1:

Unable to translate Unicode character \u2013 at index 0 to specified code page.

Here's exactly what I ran (bundled together into a .ps1):

igem install rake
igem install albacore
igem install rspec
igem install cucumber –-version "=0.6.4"
igem install iron-term-ansicolor

Tim said...

@J Wynia I haven't seen that one. I've done this on a couple VMs and stand alone boxes, haven't seen that error, but I haven't used Powershell. I'm also installing the IronRuby code for .Net 4.0, in case you're doing it for .Net 2.0. (and 1.1 is new...like wasn't there Thursday when I typed this up. :) )

One other thing to try, go to the plain ol' command prompt rather than powershell, and do them one at a time from there. You can add --no-ri --no-rdoc to each one to save installing the documentation. You can also string them together to save some typing. Example: igem install rake albacore rspec --no-ri --no-rdoc

If none of that works, you can always get in touch with the IronRuby guys: http://ironruby.net/Support

Unknown said...

Yeah. I did it first from a straight cmd.exe, but when it didn't work, I put all of the commands into a .ps1 so I wouldn't have to re-paste each line.

One at a time or all together, the cucumber gem failed with that same error.

I'm on Win7 .NET 4.0. Only tried IronRuby 1.1 because 1.0 failed for this when I ran it.


I'm going to try this on a few more machines and see if I can find a pattern. I asked, mostly in case you'd seen that particular error.