Skip to content

Instantly share code, notes, and snippets.

@donnoman
Created July 28, 2011 18:50
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save donnoman/1112243 to your computer and use it in GitHub Desktop.
Save donnoman/1112243 to your computer and use it in GitHub Desktop.
Cucumber Template
# http://rspec.info/
# http://peepcode.com/products/rspec-user-stories
# http://dannorth.net/whats-in-a-story
# http://www.lukeredpath.co.uk/2006/8/29/developing-a-rails-model-using-bdd-and-rspec-part-1
# http://www.benmabey.com/2008/05/19/imperative-vs-declarative-scenarios-in-user-stories/
# http://www.benmabey.com/2008/02/04/rspec-plain-text-stories-webrat-chunky-bacon/
# http://www.chariotsolutions.com/slides/pdfs/ete2008-IntegrationTestingWithRSpec.pdf
# http://www.joesniff.co.uk/ruby/telling-a-good-story-rspec-stories-from-the-trenches.html
# How does using stories help testing?
# * More groups can be writing stories: PM, QA, Developers
# * Results in more features being tested
# * More behaviors will be surfaced than developers may concieve on thier own
# * Test steps can be reused
# * Creating tests become more natural and clear
# * Full Stack Testing yields large code coverage gains and fill the role of integration tests.
# * Doesn't negate the need or benefits of other methods of testing, such as Unit, Functional, and Browser based testing.
# Why do we need to test so many ways?
# * The different types of testing, even user testing, surfaces different kinds of errors and in different granularity.
# * Units and Functional tests provide very granular test coverage that assists developers in quickly identifying
# where breakage occurs within the architectural model and provides confidence in refactoring within that architecture.
# * Integration/Stories provide broad testing that provides confidence that a build is ready for acceptance testing.
# * Browser based acceptance testing provides confidence that we can release the application to our customers.
# Should we use the imperative or declarative style for writing stories
# * The declarative style would be most appropriate for us because the stories are not our only source of specifications.
# Guiding Principle: Clarity over Cleverness
Story: The title should describe an activity #The story should be small enough to fit in an iteration
As a [role]
I want to [do some action]
So that [business value]
Scenario: The scenario title should say what’s different about this scenario # Start with a typical success
Given [initial state] #The givens should define all of, and no more than, the required context
And [another initial state]
When [action] #The event should describe the activity
And [another action]
Then [result] #Acceptance Criteria
And [another result]
Scenario: The scenario title should say what’s different about this scenario # follow up with other valid edge cases
Given [initial state] #The givens should define all of, and no more than, the required context
And [another initial state]
When [action] #The event should describe the activity
And [another action]
Then [result] #Acceptance Criteria
And [another result]
Scenario: The scenario title should say what’s different about this scenario # continue with a blatant invalid failure
Given [initial state] #The givens should define all of, and no more than, the required context
And [another initial state]
When [action] #The event should describe the activity
And [another action]
Then [result] #Acceptance Criteria
And [another result] #Check for a meaningful error condition
Scenario: The scenario title should say what’s different about this scenario # follow up with as many edge failures as necessary
Given [initial state] #The givens should define all of, and no more than, the required context
And [another initial state]
When [action] #The event should describe the activity
And [another action]
Then [result] #Acceptance Criteria
And [another result] #Check for a meaningful error condition
#example
Story: Animal Submission
As a visitor
I want to add a new animal to the site
So that I can share my animal knowledge with the community
Scenario: A visitor successfully submits a new animal
Given no animal named 'Alligator' exists
When visitor goes to the home page
And clicks on 'Create New Animal'
And fills in Name with 'Alligator'
And selects Phylum as 'Chordata'
And fills in Animal Class with 'Sauropsida'
And fills in Order with 'Crocodilia'
And fills in Family with 'Alligatoridae'
And fills in Genus with 'Alligator'
And checks Lay Eggs
And clicks the Create button
Then an animal named 'Alligator' should exist
And vistor should see the animal show page
And page should include a notice 'Thank you for your animal submission!'
And page should have the animal's name, phylum, animal class, order, family, and genus
# Concise Vocabulary
steps_for(:navigation) do
When "$actor goes to the home page"
When "$actor goes to $path"
Then "$actor should see the $resource show page"
# Pass the params as such: ISBN: '0967539854' and comment: 'I love this book' and rating: '4'
# this matcher will post to the resourcese default create action
When "$actor submits $a_or_an $resource with $attributes"
Then "page should include text: $text"
Then "page should include a notice '$notice_message'"
Then "page should have the $resource's $attributes"
When "clicks on '$link'"
When "fills in $field with '$value'"
When "selects $field as '$option'"
When "checks $checkbox"
When "clicks the $button button"
end
steps_for(:database) do
Given "no $resource_class named '$name' exists"
Then "$a_or_an $resource_class named '$name' should exist"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment