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
- gem update --system
- Install cucumber gem
- gem install cucumber
- Install rspec gem
- gem install rspec
- 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.
- 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" %*
- 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
- In a command prompt window, go to the cucumber gem folder under your MRI Ruby installation. The folder path might look like
- Now, run a Ruby example:
cd i18n\en icucumber features
You should see a lot of output scroll by and at the end you should see:
cd cs compile.bat icucumber features
3 scenarios (3 passed)
12 steps (12 passed)
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.
Update: Missing cs examples
As of version 0.4.3 of Cucumber, the examples\cs folder is no longer there in the code downloaded with the gem. If you like to run the above code in the post, you can download the zip file for the code at tag 0.4.2 from here. From the top, you can download the zip by clicking on the "Download Source". Then you can copy the "cs" folder to your gem installation of your current cucumber version.
Update: Get color coded display
To get a nice color coded display on your windows command line, execute the following: