Tuesday, January 29, 2013

My first contribution to Cucumber

Cucumber is a tool for doing Behaviour Driven Development using a "business-readable domain-specific language". I first met Cucumber when I was learning Ruby on Rails, and I was instantly hooked. However, it was the concept of Living Documentation promoted by Relish that got me sold. If you haven't tried Cucumber or Relish yet, I suggest you visit their website and see what's all the fuzz about. Warning: it may forever change how you do web development.

When I started working with Node.js I was pleased to find Cucumber.js, a port of Cucumber for Javascript. Since I couldn't find a port of Relish, I decided to do something similar by parsing my Cucumber files and displaying them with docpad.

Soon enough I ran into this bug, and after doing some debugging I found out the issue was coming from the Gherkin parser (Gherkin is the language Cucumber uses under the hood to convert files from a business-readable format into working tests).

The culprit was a for...in loop being executed on an array, which iterated over some of the array's properties instead of limiting itself to the array's contents. Javascript's for..in is supposed to be used on objects, not arrays, so the fix was pretty simple: change the for...in with a good old for loop.

Gherkin version 2.6.11 was released today, and to my surprise I was credited for contributing with my little bug fix. I couldn't be happier to contribute to such a great project.

No comments: