I will not go into how cool Cucumber is and all that because it is already established. If you have not experienced it, I think you should. It will make a big difference in how you look at code, testing and TDD.
I started using Cucumber on Ruby on Rails projects and I wanted to use it on .NET/C# projects. So, I will in very clear steps show you how to get Cucumber going for your C# projects. This post is just a primer to get your feet wet, but I will come back with follow up posts that will show a more complete project. So, here goes.
Step 1: Setup Ruby (MRI)
- Download Ruby
- Install Ruby (MRI version)
- Check version of ruby and rake
- ruby -–version
- rake -–version
- Update RubyGems
Step 2: Setup Cucumber and RSpec using MRI gem
- Install cucumber gem
- Install rspec gem
Step 3: Setup IronRuby
- Download IronRuby
- Install IronRuby. I had to just unzip the file I downloaded into C:\IronRuby folder. You can pick any folder or choose to build IronRuby from source.
Step 4: Create a Cucumber wrapper for IronRuby
- We need to create a script that will execute Cucumber under IronRuby very similar to cucumber.bat in your MRI Ruby folder. I have my MRI Ruby installed at C:\ruby.
- Create a new icucumber.bat file in your MRI Ruby folder with the following contents:
@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" %*
Check to see if Cucumber under IronRuby works- icucumber –help
- you should see something as below. The output has been cut to preserve space.
Usage: cucumber [options] [ [FILE|DIR|URL][:LINE[:LINE]*] ]+
cucumber examples/i18n/en/features
cucumber --language it examples/i18n/it/features/somma।feature:6:98:113
cucumber -s -i http://rubyurl.com/eeCl
Step 5: Checkout some examples
- In a command prompt window, go to the cucumber gem folder under your MRI Ruby installation. The folder path might look like
C:\ruby\lib\ruby\gems\1.8\gems\cucumber-<version>\examples
cd i18n\en
icucumber features
Now, for the litmus test, run a C# example: cd cs
compile.bat
icucumber features
You should see a lot of output scroll by and at the end you should see:
3 scenarios (3 passed)
12 steps (12 passed)
0m0.493s
Bliss! You have Cucumber running under IronRuby and running Cukes (that is what cucumber features are called) for your C# .NET code.
Feedback: I would like to hear from you about your experience running Cucumber for your C# projects.
Resources
IronRuby/Ruby Links
IronRuby website
IronRuby Wiki
Ruby website
Cucumber Screencasts
http://railscasts.com/episodes/155-beginning-with-cucumber
http://railscasts.com/episodes/159-more-on-cucumber
Cucumber Presentations