background preloader


Facebook Twitter

Dr Nic's Cucumber: building a better World (object) How to write helper libraries for your Cucumber step definitions and how to upgrade your support libraries from Cucumber 0.2 to 0.3 (released today).

Dr Nic's Cucumber: building a better World (object)

In cucumber, each scenario step in a .feature file matches to a Given, When, Then step definition. The step definitions are normal Ruby code. First class, bonnified, honky-tonk Ruby code. And what’s the one thing we love to do to Ruby code on a rainy Sunday afternoon? Refactor it. In Cucumber we use a special, until-now unknown, magic technique for refactoring step definitions. When /I fill in the Account form/ do fill_in("account_name", :with => "Mocra") fill_in("account_abn", :with => "12 345 678 901") click_button("Submit") end Could be refactored into: Cucumber Backgrounder · cucumber/cucumber Wiki.

Or: How I Learned to Stop Worrying and Love Testing Start Behaving Introduction Cucumber is a tool that implements a Behaviour Driven Design (BDD) workflow.

Cucumber Backgrounder · cucumber/cucumber Wiki

This document deals principally with initial set up and first use of the Cucumber-Rails and Cucumber Rubygems. It takes as its background the Ruby on Rails (RoR) web application framework. Detailed discussion of Behaviour Driven (BDD), Test Driven (TDD), and Panic Driven Development (SNAFU aka Cowboy Coding) can be found elsewhere. You will find some familiarity with the Ruby language helpful and of the RoR framework somewhat less so. Details regarding installing the Cucumber Rubygem and its recommended support tools for RoR are found on this wiki under the heading Ruby on Rails.

Note that in this document I often use the terms testing and test where BDD practitioners prefer the terms behaviour and expectation. Where to Start? Before anything else make sure that you have the cucumber-rails installed properly into your RoR project. Please don't use Cucumber. Cucumber is by far my least favorite thing in the Ruby ecosystem, and also the worst example of cargo cult programming.

Please don't use Cucumber

Cucumber has almost no practical benefit over acceptance testing in pure Ruby with Capybara. I understand the philosophical goals behind behavior driven development, but in the real world, Cucumber is a solution looking for a problem. The fact that Cucumber has gained the popularity it has in the Ruby community is outright baffling to me. All the reasons to use it that people give are theoretical, and I have never seen them matter or be remotely applicable in the real world. Cucumber aims to bridge the gap between software developers and non-technical stakeholders, but the reality is that product managers don't really care about Gherkin. There are basically two extremes of Cucumber: Writing Gherkin describing the feature at a very high level, and reusing few of the step definitions between features.

Everything in between is just a bad compromise of one or the other. Tips for writing better Cucumber steps by Arjan van der Gaag. Cucumber is a nice way of documenting user-level acceptance tests in web applications.

Tips for writing better Cucumber steps by Arjan van der Gaag

I’m not a huge fan of it myself, because the collection of step definitions in a typical project tends to grow into an unwieldy mess — but when I do use Cucumber in Rails projects, I tend to use a couple of tricks to keep my steps sane. Here are some of the non-obvious tricks. 1. Use markup conventions to write generic steps We want to avoid having to write thousands of step definitions. Then(/^I see (\d+) (.*?) You can use this step when you have view templates that display records in tables, to test that a certain number of records is displayed. Charlierudolph/cucumber_lint. File: README — Documentation for cucumber (2.1.0) The Truth about BDD - Clean Coder. I really like the concept of BDD (Behavior Driven Development).

The Truth about BDD - Clean Coder

I think Dan North is brilliant, and had done us all a great service by presenting the concept. It’s not so much a “but” as an “aha!”. (The punch line is at the end of this article, so don’t give up in the middle.) BDD is a variation on TDD. Whereas in TDD we drive the development of a module by “first” stating the requirements as unit tests, in BDD we drive that development by first stating the requirements as, well, requirements. For example, GIVEN an employee named Bob making $12 per hour. The Given/When/Then convention is central to the notion of BDD. The argued benefit is that the language you use affects the way you think (See this. and so if you use a language closer to the way humans think about problems, you’ll get better thought processes and therefore better results.

To say this differently, the Given/When/Then convention stimulates better thought processes than the AssertEquals(expected, actual); convention. Projects Using Cucumber · cucumber/cucumber Wiki. Complete Mac Setup Guide for Ruby+Cucumber+Watir/Selenium. Have seen quite some people having trouble getting a proper test automation setup using cucumber and watir-webdriver or selenium-webdriver.

Complete Mac Setup Guide for Ruby+Cucumber+Watir/Selenium

Here is the minimum number of steps to get your cucumber with watir/selenium-webdriver up and running on Mac. Five Ridiculously Awesome Cucumber (and Webrat) Features. Cucumber, if you haven’t heard, is the Next Big Thing™.

Five Ridiculously Awesome Cucumber (and Webrat) Features

It affords developers the ability to write human-readable integration tests. Even though it’s only at version 0.3.101, it’s full-featured with a handful of hidden gems. Here are five of my favorites.