Hello World!
As you may have already guessed, the title of my post is influenced by Jonas Nicklas' blog post You're Cuking It Wrong. In this post and and a few others to follow, I will cover some more counter productive ways of using cucumber features that I have come across. And in this post I will show how brevity of a cucumber feature may seem appealing to a novice BDD/cucumber developer and how they end up ignoring the collaboration and communication benefits. Lets get started with an example
Does that look alright? The steps read reasonably well, with the exception of the angle brackets(<>). Now lets read the 'Given' step along with examples, ie; by substituting the variables from the 'Examples:' section.
They all read well in isolation but, the last example above changes the meaning of the step template completely from
to
And clearly it creates a lot of confusion, if the examples change the meaning of the scenario itself.
So how does anyone end up writing a scenario like that?Well, there was a phase in my cucumber learning when I knew only about 'Scenario's and was unaware of the 'Scenario Outline's. So with my limited knowledge, if I were to write scenarios for the above feature, I would have ended up with quite a few scenarios like
And so on. That is hard, quite a bit of duplication and a maintenance nightmare. Then there is the sudden enlightenment of 'Scenario Outline's and I start refactoring my scenarios to be something like below.
Now the gold card and silver card looks so similar that I feel like combining them.
That looks even better and I cannot resist my temptation remove some more duplication, and I end up with what we started with in this post.
The word 'the customer' in the 'Given' step above is not much valuable, with that in mind here is my attempt to rewrite the above scenario further.
We pretty much killed the 'Given' step. This is much more brief than having separate scenarios, however can seriously compromise understanding and communication. Consider adding few more similar given steps to the above scenario and the problems will be much more glaring.
Use examples for examples NOT behavior, and don't be deceived by the brevity.
Have you got similar experiences? Have some thoughts/suggestions/comments? Will be delighted to hear.
In my next post I will cover how 'Data vs Information' matters for cucumber scenarios.
P.S.This blog post was updated with Syntax Highlighting for Cucumber to improve readability.
Friday, May 27, 2011
Syntax Highlighting For Cucumber with Custom Brush
When I tried reading my first post Cuke it Right - Brevity vs Clarity of Cucumber Features in a browser, I got bored soon by the monotony of text styling and the fact that cucumber feature steps does not distinguish themselves from the rest of the contents. Thankfully I found Alex Gorbatchev's Syntax Highlighter.
After a bit of searching in the internet I could not find a good brush for Cucumber Features and I started putting together one and ended up with the following cuke brush. If you like the brush and is familiar with adding a brush to Syntax Highlighter, stop reading now and copy the following brush code. If you like the brush and not familiar with how to use it keep reading.
If you would like to host the Syntax Highlighter on your own you can download it here and follow the installation manual. If you would like to use a hosted version, like I did this for this blog, you can find the details in this blog.
OK, its all good till now and I am able to use the built in brushes. How do I use this Cucumber Brush?
Using your own hosted version:
1. Unzip the Syntax Highlighter zip file
2. Create a file <Syntax Highlighter>/scripts/shBrushCuke.js
3. Copy the brush code to shBrushCuke.js file. Done! But if you like some testing continue
4. Open <Syntax Highlighter>/tests/brushes_tests.html
5. Add the following lines between <head> and </head> tags
6. Look for the following section of code and add 'Cuke' to the list
7. The brushes_tests.html expects a 'cuke.html' file under the brushes directory. So create one.
8. And put your Cucumber feature between the script tags
Using Free Hosted Version:
1. Include the scripts and css files as described in this blog
2. Copy and paste the brush code between lt;head> and </head> tags
If everything is alright, you should see the feature syntax highlighted like below
For more examples and usages you can look at my updated first post Cuke it Right - Brevity vs Clarity of Cucumber Features.
Comments, Suggestions or Improvements?
After a bit of searching in the internet I could not find a good brush for Cucumber Features and I started putting together one and ended up with the following cuke brush. If you like the brush and is familiar with adding a brush to Syntax Highlighter, stop reading now and copy the following brush code. If you like the brush and not familiar with how to use it keep reading.
If you would like to host the Syntax Highlighter on your own you can download it here and follow the installation manual. If you would like to use a hosted version, like I did this for this blog, you can find the details in this blog.
OK, its all good till now and I am able to use the built in brushes. How do I use this Cucumber Brush?
Using your own hosted version:
1. Unzip the Syntax Highlighter zip file
2. Create a file <Syntax Highlighter>/scripts/shBrushCuke.js
3. Copy the brush code to shBrushCuke.js file. Done! But if you like some testing continue
4. Open <Syntax Highlighter>/tests/brushes_tests.html
5. Add the following lines between <head> and </head> tags
6. Look for the following section of code and add 'Cuke' to the list
7. The brushes_tests.html expects a 'cuke.html' file under the brushes directory. So create one.
8. And put your Cucumber feature between the script tags
Using Free Hosted Version:
1. Include the scripts and css files as described in this blog
2. Copy and paste the brush code between lt;head> and </head> tags
If everything is alright, you should see the feature syntax highlighted like below
For more examples and usages you can look at my updated first post Cuke it Right - Brevity vs Clarity of Cucumber Features.
Comments, Suggestions or Improvements?
Subscribe to:
Comments (Atom)