Behavior Driven Development with Cucumber

46,256 views
45,831 views

Published on

Published in: Technology
4 Comments
67 Likes
Statistics
Notes
No Downloads
Views
Total views
46,256
On SlideShare
0
From Embeds
0
Number of Embeds
5,502
Actions
Shares
0
Downloads
1,369
Comments
4
Likes
67
Embeds 0
No embeds

No notes for slide

Behavior Driven Development with Cucumber

  1. 1. Behavior Driven Development Cucumber with Brandon Keepers ● Collective idea ● http://opensoul.org http://flickr.com/photos/nickatkins/527421404/
  2. 2. Feature: Cucumber In order to share the love As a presenter I will demonstrate behavior driven development with Cucumber Scenario: Behavior Driven Development with Cucumber Given a desire for higher quality software And a tool that executes feature documentation written in plain text When you watch this presentation Then you will gain an understanding of behavior driven development And see examples of behavior driven development with cucumber And be equipped to integrate Cucumber into your development process
  3. 3. Quality
  4. 4. 1 Quality meets requirements
  5. 5. Developer Language Client
  6. 6. Developer Stories Client
  7. 7. In order to keep of track movies that I want to see As a NetFlix customer I can add movies to a queue http://dannorth.net/whats-in-a-story
  8. 8. va l ue p ro p o s i t i o n In order to keep of track movies that I want to see As a NetFlix customer I can add movies to a queue http://dannorth.net/whats-in-a-story
  9. 9. In order to keep of track movies that I want to see As a NetFlix customer role I can add movies to a queue http://dannorth.net/whats-in-a-story
  10. 10. In order to keep of track movies that I want to see As a NetFlix customer I can add movies to a queue e at u re f http://dannorth.net/whats-in-a-story
  11. 11. 2 Quality works as expected
  12. 12. Test Driven
  13. 13. Behavior Driven
  14. 14. Verify
  15. 15. Confidence
  16. 16. Design
  17. 17. Behavior
  18. 18. Testing Specifying
  19. 19. Cucumber http://flickr.com/photos/nickatkins/527421404/
  20. 20. rbehave rSpec Story Runner Cucumber
  21. 21. http://github.com/aslakhellesoy/cucumber
  22. 22. $ gem install cucumber
  23. 23. Rakefile require 'rubygems' require 'cucumber/rake/task' Cucumber::Rake::Task.new
  24. 24. $ rake features
  25. 25. Rails $ ruby script/plugin install git://github.com/aslakhellesoy/cucumber.git git://github.com/brynary/webrat.git git://github.com/dchelimsky/rspec.git git://github.com/dchelimsky/rspec-rails.git $ ruby script/plugin install git://brandon.local/cucumber git://brandon.local/webrat git://brandon.local/rspec git://brandon.local/rspec-rails
  26. 26. Dependencies $ gem install term-ansicolor treetop diff-lcs hpricot
  27. 27. $ ruby script/generate cucumber
  28. 28. Feature: Manage companies In order to keep track of companies A user Should be able to manage companies Scenario: Create a new company Given I am logged in When I create a new company named Acme Then I should see that a company named Acme exists
  29. 29. features/ companies.feature steps/ company_steps.rb
  30. 30. Given == Setup Given quot;I am logged inquot; do user = Factory(:user) visits new_session_path fills_in ‘Login’, :with => user.login fills_in ‘Password’, :with => user.password clicks_button ‘Login’ end
  31. 31. Given quot;I am logged inquot; do user = Factory(:user) f ac t o r y_g i r l visits new_session_path fills_in ‘Login’, :with => user.login fills_in ‘Password’, :with => user.password clicks_button ‘Login’ end Factory.sequence(:email) {|n| quot;user#{n}@example.comquot; } Factory.define :user do |user| user.name 'User' user.email { Factory.next(:email) } user.login {|u| u.email } user.password 'password' user.password_confirmation 'password' end
  32. 32. Given quot;I am logged inquot; do user = Factory(:user) visits new_session_path fills_in 'Login', :with => user.login fills_in 'Password', :with => user.password clicks_button 'Login' end we b rat
  33. 33. When == Change When quot;I create a new company named $namequot; do |name| visits new_company_path fills_in 'Name', :with => name clicks_button 'Create' end
  34. 34. When == Change v a r i a ble When quot;I create a new company named $namequot; do |name| visits new_company_path fills_in 'Name', :with => name clicks_button 'Create' end When I create a new company named Acme
  35. 35. Then == Outcome Then quot;I should see that a company named $name existsquot; do |name| response.body.should =~ Regexp.new(name) end
  36. 36. Feature: Manage companies In order to keep track of companies A user Should be able to manage companies Scenario: Create a new company Given I am logged in When I create a new company named Acme Then I should see that a company named Acme exists 3 steps passsed
  37. 37. Scenario: Paging through leads and rejecting Given a company called Apple Corp. And a company called Pear Inc. And a list for Client A And Apple Corp. is a new lead in a list for Client A And Pear Inc. is a new lead in a list for Client A And I am logged in as a staff member When I view the company overview for Apple Corp. And I reject Apple Corp. And I go to the next lead Then I see the company overview for Pear Inc.
  38. 38. Cucumber or RSpec?
  39. 39. Cucumber or RSpec? BOTH
  40. 40. http://github.com/bmabey/cucumber-tmbundle/
  41. 41. Feature: Cucumber In order to share the love As a presenter I will demonstrate behavior driven development with Cucumber Scenario: Behavior Driven Development with Cucumber Given a desire for higher quality software And a tool that executes feature documentation written in plain text When you watch this presentation Then you will gain an understanding of behavior driven development And see examples of behavior driven development with cucumber And be equipped to integrate Cucumber into your development process 6 steps passed
  42. 42. @bkeepers github.com/ brandon collectiveidea opensoul.org sessions.collectiveidea.com

×