Cucumber Crash Course

download Cucumber Crash Course

of 21

  • date post

    03-Dec-2014
  • Category

    Technology

  • view

    2.019
  • download

    1

Embed Size (px)

description

This presentation was the kick-off for the brown-bag series of learning sessions that AgilityFeat.com is hosting for their software development teams.

Transcript of Cucumber Crash Course

  • 1. presentsRELEASE THE GHERKIN!2012 AgilityFeat Inc

2. 2012 AgilityFeat, Inc. 3. What it is Straight-forward language Common Language Communication Tool Concrete Examples Describes behavior 2012 AgilityFeat, Inc. 4. #protipmake readability your main goal.Otherwise, a reader can easily feel morelike theyre a reading computer programthan a specification document- Aslak Hellesy (creator of Cucumber) 2012 AgilityFeat, Inc. 5. Cucumbers Natural Habitat 2012 AgilityFeat, Inc. 6. Features Plain text Filename ends in .feature Describes behavior of system Lives in features directoryStep Ruby codeDefinitionsFilename ends in.rb Does regex match of text from feature files Lives in features/step_definition directoryRuby Magic Your preferred gems go here Referenced in features/support/env.rbApplicationWe will be testing a web-pageUnder Test 2012 AgilityFeat, Inc. 7. ExampleFeature: Brown Bag DemoScenario: Google Search Given I am on http://www.google.com When I search for Hello World Then I should see results containing the search phrase 2012 AgilityFeat, Inc. 8. SolutionGiven /^I am on (*^+*)$/ do |arg1|visit(arg1)endWhen /^I search for (*^+*)$/ do |arg1|@search_phrase = arg1within(:css, #gbqfqw) dofill_in q, :with => @search_phraseendendThen /^I should see results containing the search phrase$/ dopage.should have_content(@search_phrase)end 2012 AgilityFeat, Inc. 9. Feature: Class DemonstrationScenario: Show a Hello WorldGiven I want to say Hello World!When I execute the applicationThen I should see the message 2012 AgilityFeat, Inc. 10. Feature: Class DemonstrationScenario: Show a Hello WorldGiven I want to say Hello World!When I execute the applicationThen I should see the messageAnd it should be italicBut it should not be bold 2012 AgilityFeat, Inc. 11. Feature: Class DemonstrationScenario: Show a Hello World* I want to say Hello World!* I execute the application* I should see the message* it should be italic* it should not be bold 2012 AgilityFeat, Inc. 12. Feature: Class DemonstrationScenario: Show a Hello WorldGiven I want to say Hello World!When I execute the applicationThen I should see the messageAnd it should be italicBut it should not be bold 2012 AgilityFeat, Inc. 13. Feature: Class DemonstrationIn order to expose you to new ideasAs an instructorI want to show you an end-to-end exampleScenario: Show a Hello WorldGiven I want to say Hello World!When I execute the applicationThen I should see the messageAnd it should be italicBut it should not be bold 2012 AgilityFeat, Inc. 14. Feature: Class DemonstrationAs an instructorI would like to show an end-to-end exampleSo that I can expose you to new ideasBackground:Given I want to say Hello World!When I execute the applicationThen I should see the messageScenario: Show an italicized Hello World And it should be italicScenario: Show a bold Hello World But it should not be2012 AgilityFeat, Inc.bold 15. Feature: International DisplayScenario: Display Hello World in English Given I want to say Hello World! When I execute the application And I specify English as the language Then the output should be Hello World!Scenario: Display Hello World in Spanish Given I want to say Hello World! When I execute the application And I specify Spanish as the language Then the output should be Hola, mundo!Scenario: Display Hello World in German Given I want to say Hello World! When I execute the application And I specify German as the language Then the output should 2012 AgilityFeat, Inc. be Hallo Welt! 16. Feature: Internationalize Hello WorldScenario Outline: Display in multiple languages Given I want to say Hello World! When I execute the application And I specify as the language Then the output should be Examples: | language| output| | English | Hello World!| | Spanish | Hola, mundo! | | German| Hallo Welt! | 2012 AgilityFeat, Inc. 17. Feature: Travel The WorldScenario: Keep Track Of VisitsGiven a list like this:| Location | Times visited || Costa Rica |0|| Germany|0|When I travel to Costa RicaThen the list should look like this:| Location | Times visited || Costa Rica |1|| Germany|0| 2012 AgilityFeat, Inc. 18. Doc stringsScenario: Look up hostel reservation e-mailWhen I search for Alexander HouseThen I should see the following message:"""Welcome Mr. Haeffner.Youll be staying in the bunk house this visit.Please refrain from stealing our towels (again)."" 2012 AgilityFeat, Inc. 19. Recap -- Features Plain text files that end in .feature They live in the root of the features directory Given, When, Then, And, But are trigger words They matter most for readability Descriptive text can go at the top There are several approaches to abstract featuresand make them more readable Usage depends on intent & team understanding 2012 AgilityFeat, Inc. 20. Recap -- Step Definitions Ruby files that live in features/step_definitions Matches plain text from feature files Stores it into a variable You can set this to a class level variable for useacross your test scenario Use a gem to get where you need to go (e.g.Capybara for web testing) 2012 AgilityFeat, Inc. 21. Recap -- System Setup Gems you want to use can be added to env.rb It lives in the features/support directory If/when you create helper methods, create a rubyfile and place them in this directory If you add something to your test harness andexecution order is important, place it in env.rb itloads before everything else 2012 AgilityFeat, Inc.