Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cucumber: It's about Talking not Testing

Cucumber: It's about Talking not Testing

Many people use Cucumber purely as an end-to-end testing tool, and often wonder why they’re bothering to use it over something like Steak: they reason that if they’re the only ones reading the feature files, why bother having the plain text features? Others find that the cost of maintaining Cucumber features after a while outweighs the benefits of using them, and stop using it altogether.

Both these conclusions stem from seeing cucumber purely as a testing tool: whereas it’s actually an extraordinarily powerful communication tool designed to facilitate the discussion of behaviour between those to write code and those who don’t, and only incidentally a testing tool.

Learn about a proven and powerful way to use Cucumber which leads to maintainable code, features your customer actually reads, clearer communication and understanding on your project, and as a bonus ensures your code behaves correctly over time.

chrismdp

June 29, 2012
Tweet

More Decks by chrismdp

Other Decks in Programming

Transcript

  1. Feature: User orders plant As a user of the website,

    I want to place an order on the website, so that I can order a plant through the website Scenario: User orders plant Given there is a plant with name: “Plant 1”, price: “£1”, size: “large”, foliage: “foliage 1” When I visit the homepage And I click on “Plant 1” And I click “Add” Friday, 29 June 12
  2. And I fill in “City” with “City 1” And I

    fill in “Postcode” with “SW1A 1AA” And I click “Continue” And I click “Continue” And I fill in “Card number” with “1234 1234 1234 1234” And I fill in “Expiry date” with “00/00” And I fill in “Name on Card” with “Name on Card 1” And I fill in “CV2” with “123” And I click “Place Order” Then I should receive an email Friday, 29 June 12
  3. “...but with a way for those who love gardening to

    make it a whole interactive experience, right?” Friday, 29 June 12
  4. “So gardeners can create like an ‘area’ to put pictures

    of their plants...” Friday, 29 June 12
  5. “...and other gardeners can say what they think, and suggest

    garden layout improvements...” Friday, 29 June 12
  6. “Users herp derp account derpety users#show derp photos (hmm, EC2

    storage; which gem? Add day to estimate)” Friday, 29 June 12
  7. Feature: User orders plant As a user of the website,

    I want to place an order on the website, so that I can order a plant through the website Scenario: User orders plant Given there is a plant with name: “Plant 1”, price: “£1”, size: “large”, foliage: “foliage 1” When I visit the homepage And I click on “Plant 1” And I click “Add” Friday, 29 June 12
  8. And I fill in “City” with “City 1” And I

    fill in “Postcode” with “SW1A 1AA” And I click “Continue” And I click “Continue” And I fill in “Card number” with “1234 1234 1234 1234” And I fill in “Expiry date” with “00/00” And I fill in “Name on Card” with “Name on Card 1” And I fill in “CV2” with “123” And I click “Place Order” Then I should receive an email Friday, 29 June 12
  9. Given /there (?:is|are) (a|\d+) (\w+) with ((\w+): (\w+) )+$/ do

    |count, name, fields| count = count == “a” ? 1 : count.to_i params = {} fields.each do |field| params[field[0]] = field[1] end count.times { name.classify.create! (params) } end Friday, 29 June 12
  10. “...but with a way for those who love gardening to

    make it a whole interactive experience, right?” Friday, 29 June 12
  11. “So gardeners can create like an ‘area’ to put pictures

    of their plants...” Friday, 29 June 12
  12. “...and other gardeners can say what they think, and suggest

    garden layout improvements...” Friday, 29 June 12
  13. Feature: User orders plant As Gareth the aspiring gardener, I

    want to buy plants I’ve seen shared on other gardeners uploaded layouts, so that I can improve my own garden with ideas from others Friday, 29 June 12
  14. Scenario: Gareth buys plants When “Gareth” buys a recommended plant

    Then the order should be placed Friday, 29 June 12
  15. Scenario: Gareth supplies incorrect information When “Gareth” enters incorrect information

    during a purchase Then he is shown an appropriate error And the order does not get placed Friday, 29 June 12
  16. When /^“(.+)” buys a recommended plant$/ do |name| place_order(user_for(name)) end

    Then /^the order should be placed$/ do |name| check_order_placed(user_for(name)) end Friday, 29 June 12
  17. When /^“(.+)” enters incorrect information during a purchase$/ do |name|

    place_order(user_for(name)) do fill_in :credit_card, :with => “bad” end end Friday, 29 June 12
  18. def user_for(name) User.find_by_name(name) || User.create(:name => name) end def place_order(user)

    visit order_path fill_in :name, :with => user.name yield if block_given? click_button “Submit” end Friday, 29 June 12