Cucumber
February 10th 2011Experiment! Danger! Beware! As you may have gathered, this blog is turning into an odd collection of writing. This one is certainly no exception, but I do plan to return to something closer to English next time. Good luck!
[file::features/blog_post.feature]
Feature: Talk about Cucumber
In order to explore Outside-in BDD
As a idiot non-savant
I want to describe why I like it
Scenario: You don't get it, at all
Given that this seems like a waste of time
When there is real code to write
Then have a think about why you don't normally automate functional tests
Scenario: No-one has told me what the Cucumber thing helps with yet
Given that it's mentioned it in the title
When so far all I've seen is a sort of Shakespearen sonnet-bot on crack
Then there should be an explanation of what Cucumber does and why it helps
But stop with the weird text layout
>cucumber features
(::) failed steps (::)
Failing Scenarios:
All, especially this blog post
[file::features/step_definitions/explanation_step.rb]
Given /^that this seems like a waste of time$/ do p "
The thing to consider is that this isn’t about testing, it’s about working incrementally by describing the behavior in a human-ish Domain Specific Language. The tests act as markers of your progress, and the failures act as the pointers of what to do next.
"
end
When /^there is real code to write$/
do p "
Which now has the advantage of linking the description of what you want to do to the real code.
"
end
Then /^have a think about why you don't normally automate functional tests$/
do p "
Functional tests are tiresome and they break because they are brittle, in that they don’t link and live with the code but are produced as a separate thing that then takes on a life of its own. By placing them as part of the work process, as the driver for the work, then you get the advantage of tests too.
The behavior description helps you work out what to do and the tests then help you have the confidence to change the behavior over time.
"
response.should contain("Oh, I get it - cool. Can I go now?")
assert(false)
end
Given /^that it's mentioned it in the title$/
do p "
Yes, there it is. In the title, I’ll get to it in a bit – honest.
"
end
When /^so far all I've seen is a sort of Shakespearen sonnet-bot on crack$/
do p "
Yes, I know. I’m actually starting to regret it too if that makes you feel any better.
"
end
Then /^there should be an explanation of what Cucumber does and why it helps$/
do p "
Cucumber is a ruby DSL (the grammar is called Gherkin, of course) that describes simple steps of behavior that then map onto specific tests as part of your steps definition. It works really well when combined with things like Rspec2 and web test automation such as Capybara or webrat.
I like Cucumber because it has filled a gap for me of avoiding getting into a rut early on in terms of ‘Why am I asserting for 1 == 1’ style testing and being intrusive (in a good way) on how I was doing TDD. I’ve found that it helps clarify what I want to achieve in code before I write too much, and liberates the feeling of racing ahead too many steps.
The ‘Out-side in’ style has been very useful to avoid too much over-design too early, and the tools light enough not to get in the way. If you get the opportunity to try it then I recommend it.
"
end
But /^stop with the weird text layout$/
do p "
Ok, I’m done now, plus this was just an excuse to write about BDD using BDD. If it still doesn’t make any sense then here’s some links I’ve personally found really useful:
http://www.pragprog.com/titles/achbd/the-rspec-book
http://www.engineyard.com/blog/2009/cucumber-introduction/
http://www.sarahmei.com/blog/2010/05/29/outside-in-bdd/
"
>cucumber features
Pass, well, if a 'D' is still considered a pass nowadays.