In this article, we will delve into the process of getting a Debugger working for cucumber inside visual Studio using Ruby in Steel.
If you have never seen Ruby in Steel. I highly recommend it, so go check it out at http://www.sapphiresteel.com/.
If you have never used cucumber from within visual studio, check out Brendan Erwin’s article on “Quick and Easy Cucumber Integration in Visual Studio.
Done with all that? Good let’s get started!
Go to the link above and download/install Ruby in Steel (RiS), they offer a 60-day trial license so you have plenty of time to play around with it.
Once installed, open up visual studio, to any project you would like to add cucumber integration to. Right-Click on the solution, and add a new ruby project.
Create your cucumber files & folder structure.
Now comes the interesting part. In order to get cucumber to run within RiS, you’ll need to define an entry point for cucumber so that the RiS debugger can load the debugging symbols.
There are many ways to do this, when I first attempted to tackle this problem, I took the cucumber ruby file and added it to my solution…but I couldn’t figure out how to make it only run the scenarios I wanted.
Along came the C# helper program!
Basically, what this program does is take 3 command line arguments: Project Directory, Item Path, and optionally Current Line and saves them to a file called “debuginfo.dbg”. It also takes an embedded resource, cucumber.rb and and writes it to the ruby directory for use as well. This ruby fill will be the entry point for our debugger. It takes all the parameters from the “debuginfo.dbg” file and kicks off cucumber with those params.
You can download the full C# solution here: CucumberDebugger.zip
Now we need to create an external tool that will call our CucumberDebugger.exe with the parameters we need.
Create a new tool called Cucumber Debug (Scenario) with the settings below:
Arguments (for ease of copy/paste): $(ProjectDir) $(ItemPath) $(CurLine)
Now go to your *.feature file, choose the scenario to run (place your cursor there), and run your external tool.
This will create 2 files at C:\ruby\bin. “cucumberDebugger.rb” and “debuginfo.dbg'”
All we need to do now, is tell the debugger to look for our entry point file, and kick it off.
Right-Click on your ruby project and go to “Properties”, then the build tab.
Set your ruby start file to: C:\ruby\bin\CucumberDebugger.rb, save and close.
Go back to your feature file and click Run!
You can now step through your ruby code just like any other .net file!
Please let me know if you have any questions.