Post on 03-Dec-2014
description
presents
RELEASE THE GHERKIN!©2012 AgilityFeat Inc
© 2012 AgilityFeat, Inc.
© 2012 AgilityFeat, Inc.
What it is
• Straight-forward language• Common Language• Communication Tool• Concrete Examples• Describes behavior
© 2012 AgilityFeat, Inc.
#protip
“make readability your main goal. Otherwise, a reader can easily feel more like they’re a reading computer program than a specification document” - Aslak Hellesøy (creator of Cucumber)
© 2012 AgilityFeat, Inc.
Cucumber’s Natural Habitat
© 2012 AgilityFeat, Inc.
Features
Step Definitions
Ruby Magic
Application Under Test
Plain textFilename ends in .featureDescribes behavior of systemLives in features directory
Ruby codeFilename ends in.rbDoes regex match of text from feature filesLives in features/step_definition directory
Your preferred gems go hereReferenced in features/support/env.rb
We will be testing a web-page
© 2012 AgilityFeat, Inc.
Feature: Brown Bag Demo
Scenario: Google SearchGiven I am on “http://www.google.com”When I search for “Hello World”Then I should see results containing the search phrase
Example
© 2012 AgilityFeat, Inc.
SolutionGiven /^I am on “([^”]*)”$/ do |arg1|
visit(arg1)end
When /^I search for “([^”]*)”$/ do |arg1|@search_phrase = arg1within(:css, “#gbqfqw”) dofill_in ‘q’, :with => @search_phraseend
end
Then /^I should see results containing the search phrase$/ dopage.should have_content(@search_phrase)
end
© 2012 AgilityFeat, Inc.
Feature: Class Demonstration
Scenario: Show a Hello WorldGiven I want to say “Hello World!”
When I execute the application Then I should see the message
© 2012 AgilityFeat, Inc.
Feature: Class Demonstration
Scenario: Show a Hello WorldGiven I want to say “Hello World!”
When I execute the application Then I should see the message
And it should be italicBut it should not be bold
© 2012 AgilityFeat, Inc.
Feature: Class Demonstration
Scenario: 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.
Feature: Class Demonstration
Scenario: Show a Hello WorldGiven I want to say “Hello World!”
When I execute the application Then I should see the message
And it should be italicBut it should not be bold
© 2012 AgilityFeat, Inc.
Feature: Class DemonstrationIn order to expose you to new ideasAs an instructorI want to show you an end-to-end example
Scenario: Show a Hello WorldGiven I want to say “Hello World!”
When I execute the application Then I should see the message
And it should be italicBut it should not be bold
© 2012 AgilityFeat, Inc.
Feature: Class DemonstrationAs an instructorI would like to show an end-to-end exampleSo that I can expose you to new ideas
Background: Given I want to say “Hello World!”When I execute the applicationThen I should see the message
Scenario: Show an italicized Hello WorldAnd it should be italic
Scenario: Show a bold Hello WorldBut it should not be bold
© 2012 AgilityFeat, Inc.
Feature: International Display
Scenario: Display Hello World in EnglishGiven I want to say “Hello World!”When I execute the applicationAnd I specify English as the languageThen the output should be “Hello World!”
Scenario: Display Hello World in SpanishGiven I want to say “Hello World!”When I execute the applicationAnd I specify Spanish as the languageThen the output should be “¡Hola, mundo!”
Scenario: Display Hello World in GermanGiven I want to say “Hello World!”When I execute the applicationAnd I specify German as the languageThen the output should be “Hallo Welt!”
© 2012 AgilityFeat, Inc.
Feature: Internationalize Hello World
Scenario Outline: Display in multiple languagesGiven I want to say “Hello World!”When I execute the applicationAnd I specify “<language>” as the languageThen the output should be “<output>”
Examples:| language | output |
| English | Hello World! | | Spanish | ¡Hola, mundo! |
| German | Hallo Welt! |
© 2012 AgilityFeat, Inc.
Feature: Travel The World
Scenario: Keep Track Of Visits Given 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.
Doc strings
Scenario: Look up hostel reservation e-mailWhen I search for “Alexander House”Then I should see the following message:""" Welcome Mr. Haeffner.You’ll be staying in the bunk house this visit.Please refrain from stealing our towels (again).""”
© 2012 AgilityFeat, Inc.
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 features
and make them more readable• Usage depends on intent & team understanding
© 2012 AgilityFeat, Inc.
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 use
across your test scenario• Use a gem to get where you need to go (e.g.
Capybara for web testing)
© 2012 AgilityFeat, Inc.
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 ruby
file and place them in this directory• If you add something to your test harness and
execution order is important, place it in env.rb – it loads before everything else