SlideShare una empresa de Scribd logo
1 de 34
UPenn on Rails
Lesson 2: User Stories and Testing
User Stories

  Testing
How’s it going?

Got some Players?

 Is it on GitHub?

    Heroku?
User Stories
(pivotal tracker)
In order to [value]

As a [actor]

I want [feature]
Players feature?
In order to know who is on a team

As a league manager

I want to see a list of players on
the team page
Feature: Player listings
  In order to know who is on a team
  As a league manager
  I want to see a list of players on the team page

  Scenario: listing on a team page
    Given I am on the teams page
    When I follow "Ballshevicks"
    Then I should see "Trotter"
Cucumber
Feature: Player listings
  In order to know who is on a team
  As a league manager
  I want to see a list of players on the team page

  Scenario: listing on a team page
    Given I am on the teams page
    When I follow "Ballshevicks"
    Then I should see "Trotter"
User Stories
as Integration Tests
Setting up Cucumber
1. Add `group :development, :test` to Gemfile
2. Add ‘cucumber-rails’, ‘capybara’ and
   ‘database_cleaner’ in that group
3. Run `bundle`
4. Run `rails generate cucumber:install`
5. `$EDITOR features/players.feature`
undefined local variable or method `node' for
  #<Capybara::Driver::RackTest::Node:...>
               (NameError)

    • Comment out line 18 in features/
      support/env.rb


    • cucumber-rails 0.4.0 fixes this, but it’s still in
      beta
CODE
(setting it up)
Running a scenario


1. Put `@wip` above the scenario
2. Run `rake cucumber:wip`
CODE
(running it)
Debugging

`Then show me the page`
requires ‘launchy’ gem

`Then debug` (debugger;1)
requires ‘ruby-debug’ or ‘ruby-debug19’
CODE
(debugging it)
Building data
`$EDITOR features/support/fixtures.rb`

Before do
  Team.create(:name => "Ballshevicks")
end
• Any features/support/*.rb gets loaded

• `Before` gets run before each Scenario
Other Data Options


• Load test/fixtures/*.yml
• Use the ‘fabrication’ object factory gem
CODE
(giving it data)
Defining Steps
          When I follow "Show" in the row with "Ballshevicks"




When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|

  When %Q|I follow "#{link}" within "tr:contains('#{text}')"|

end
               features/step_definitions/table_steps.rb
Defining Steps
          When I follow "Show" in the row with "Ballshevicks"



 Regular Expression


When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|

  When %Q|I follow "#{link}" within "tr:contains('#{text}')"|

end
               features/step_definitions/table_steps.rb
Defining Steps
          When I follow "Show" in the row with "Ballshevicks"



 Regular Expression
                             Capturing groups

When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|

  When %Q|I follow "#{link}" within "tr:contains('#{text}')"|

end
               features/step_definitions/table_steps.rb
Defining Steps
          When I follow "Show" in the row with "Ballshevicks"



 Regular Expression
                             Capturing groups

When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|

  When %Q|I follow "#{link}" within "tr:contains('#{text}')"|

end
               features/step_definitions/table_steps.rb

               Definition in ruby code
web_steps.rb
Given I am on the (rake routes) page
When I press “button” / follow “link”
When I fill in “field” with “value”
When I select “option” from “field”
When I check “field”
Then I should see “text” (within “section”)
CODE
(assigning teams?)
Unit testing
Use for direct testing of

• Models (test/unit/*.rb)
• Helpers (test/unit/helpers/*.rb)
• Controllers (test/functional/*.rb)
Example:
          Player#last_name
class PlayerTest < ActiveSupport::TestCase
  test "parses out last name" do
    trotter = Player.new(:name => "Trotter Cashion")
    assert_equal "Cashion", trotter.last_name
  end
end


               (Test First! At least try.)
CODE
(run and fix it)
Homework
• Write user stories for adding and editing
  teams, players and games


• Add a username and password system
  (railscasts.com episodes 82 and 250)


• Next week: Plugins!

Más contenido relacionado

La actualidad más candente

優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
techmemo
 
jQuery Plugin Creation
jQuery Plugin CreationjQuery Plugin Creation
jQuery Plugin Creation
benalman
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
Yusuke Wada
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 

La actualidad más candente (20)

優しいWAFの作り方
優しいWAFの作り方優しいWAFの作り方
優しいWAFの作り方
 
Play á la Rails
Play á la RailsPlay á la Rails
Play á la Rails
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
 
Cakephpstudy5 hacks
Cakephpstudy5 hacksCakephpstudy5 hacks
Cakephpstudy5 hacks
 
My Adventures In Objective-C (A Rubyists Perspective)
My Adventures In Objective-C (A Rubyists Perspective)My Adventures In Objective-C (A Rubyists Perspective)
My Adventures In Objective-C (A Rubyists Perspective)
 
The Grand Puppet Sub-Systems Tour - Nicholas Fagerlund, Puppet Labs
The Grand Puppet Sub-Systems Tour - Nicholas Fagerlund, Puppet LabsThe Grand Puppet Sub-Systems Tour - Nicholas Fagerlund, Puppet Labs
The Grand Puppet Sub-Systems Tour - Nicholas Fagerlund, Puppet Labs
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
jQuery Plugin Creation
jQuery Plugin CreationjQuery Plugin Creation
jQuery Plugin Creation
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 
Findbin libs
Findbin libsFindbin libs
Findbin libs
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
How to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter KriensHow to simplify OSGi development using OBR - Peter Kriens
How to simplify OSGi development using OBR - Peter Kriens
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Building Cloud Castles - LRUG
Building Cloud Castles - LRUGBuilding Cloud Castles - LRUG
Building Cloud Castles - LRUG
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Codeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework ComponentsCodeigniter : Using Third Party Components - Zend Framework Components
Codeigniter : Using Third Party Components - Zend Framework Components
 
Mojo as a_client
Mojo as a_clientMojo as a_client
Mojo as a_client
 
YAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービスYAPC::Asia 2010 Twitter解析サービス
YAPC::Asia 2010 Twitter解析サービス
 
Sprockets
SprocketsSprockets
Sprockets
 

Destacado (6)

chef loves windows
chef loves windowschef loves windows
chef loves windows
 
2011 02-08 cucumber
2011 02-08 cucumber2011 02-08 cucumber
2011 02-08 cucumber
 
Hadoop a Natural Choice for Data Intensive Log Processing
Hadoop a Natural Choice for Data Intensive Log ProcessingHadoop a Natural Choice for Data Intensive Log Processing
Hadoop a Natural Choice for Data Intensive Log Processing
 
Node.js
Node.jsNode.js
Node.js
 
Ruby on the Phone
Ruby on the PhoneRuby on the Phone
Ruby on the Phone
 
wwc start-launched
wwc start-launchedwwc start-launched
wwc start-launched
 

Similar a UPenn on Rails pt 2

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
旻琦 潘
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Paulo Ragonha
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
Clinton Dreisbach
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
Dr Nic Williams
 

Similar a UPenn on Rails pt 2 (20)

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Riak with node.js
Riak with node.jsRiak with node.js
Riak with node.js
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Crafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in RubyCrafting Beautiful CLI Applications in Ruby
Crafting Beautiful CLI Applications in Ruby
 
Rugged Driven Development with Gauntlt
Rugged Driven Development with GauntltRugged Driven Development with Gauntlt
Rugged Driven Development with Gauntlt
 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
Doing the Refactor Dance - Making Your Puppet Modules More Modular - PuppetCo...
 
Test legacy apps with Behat
Test legacy apps with BehatTest legacy apps with Behat
Test legacy apps with Behat
 
Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3Migrating Legacy Rails Apps to Rails 3
Migrating Legacy Rails Apps to Rails 3
 
Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'Refactor Dance - Puppet Labs 'Best Practices'
Refactor Dance - Puppet Labs 'Best Practices'
 
Cucumber
CucumberCucumber
Cucumber
 
Desarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutosDesarrollando aplicaciones web en minutos
Desarrollando aplicaciones web en minutos
 
Isolated development in python
Isolated development in pythonIsolated development in python
Isolated development in python
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Integration Testing With Cucumber How To Test Anything J A O O 2009
Integration Testing With  Cucumber    How To Test Anything    J A O O 2009Integration Testing With  Cucumber    How To Test Anything    J A O O 2009
Integration Testing With Cucumber How To Test Anything J A O O 2009
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

UPenn on Rails pt 2

  • 1. UPenn on Rails Lesson 2: User Stories and Testing
  • 2. User Stories Testing
  • 3. How’s it going? Got some Players? Is it on GitHub? Heroku?
  • 6. In order to [value] As a [actor] I want [feature]
  • 8. In order to know who is on a team As a league manager I want to see a list of players on the team page
  • 9. Feature: Player listings In order to know who is on a team As a league manager I want to see a list of players on the team page Scenario: listing on a team page Given I am on the teams page When I follow "Ballshevicks" Then I should see "Trotter"
  • 10. Cucumber Feature: Player listings In order to know who is on a team As a league manager I want to see a list of players on the team page Scenario: listing on a team page Given I am on the teams page When I follow "Ballshevicks" Then I should see "Trotter"
  • 12. Setting up Cucumber 1. Add `group :development, :test` to Gemfile 2. Add ‘cucumber-rails’, ‘capybara’ and ‘database_cleaner’ in that group 3. Run `bundle` 4. Run `rails generate cucumber:install` 5. `$EDITOR features/players.feature`
  • 13. undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:...> (NameError) • Comment out line 18 in features/ support/env.rb • cucumber-rails 0.4.0 fixes this, but it’s still in beta
  • 15. Running a scenario 1. Put `@wip` above the scenario 2. Run `rake cucumber:wip`
  • 17. Debugging `Then show me the page` requires ‘launchy’ gem `Then debug` (debugger;1) requires ‘ruby-debug’ or ‘ruby-debug19’
  • 21. • Any features/support/*.rb gets loaded • `Before` gets run before each Scenario
  • 22. Other Data Options • Load test/fixtures/*.yml • Use the ‘fabrication’ object factory gem
  • 24. Defining Steps When I follow "Show" in the row with "Ballshevicks" When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|   When %Q|I follow "#{link}" within "tr:contains('#{text}')"| end features/step_definitions/table_steps.rb
  • 25. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|   When %Q|I follow "#{link}" within "tr:contains('#{text}')"| end features/step_definitions/table_steps.rb
  • 26. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groups When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|   When %Q|I follow "#{link}" within "tr:contains('#{text}')"| end features/step_definitions/table_steps.rb
  • 27. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groups When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|   When %Q|I follow "#{link}" within "tr:contains('#{text}')"| end features/step_definitions/table_steps.rb Definition in ruby code
  • 28. web_steps.rb Given I am on the (rake routes) page When I press “button” / follow “link” When I fill in “field” with “value” When I select “option” from “field” When I check “field” Then I should see “text” (within “section”)
  • 31. Use for direct testing of • Models (test/unit/*.rb) • Helpers (test/unit/helpers/*.rb) • Controllers (test/functional/*.rb)
  • 32. Example: Player#last_name class PlayerTest < ActiveSupport::TestCase   test "parses out last name" do     trotter = Player.new(:name => "Trotter Cashion")     assert_equal "Cashion", trotter.last_name   end end (Test First! At least try.)
  • 34. Homework • Write user stories for adding and editing teams, players and games • Add a username and password system (railscasts.com episodes 82 and 250) • Next week: Plugins!

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n