UPenn on Rails pt 2

983 views

Published on

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
983
On SlideShare
0
From Embeds
0
Number of Embeds
175
Actions
Shares
0
Downloads
5
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • UPenn on Rails pt 2

    1. 1. UPenn on RailsLesson 2: User Stories and Testing
    2. 2. User Stories Testing
    3. 3. How’s it going?Got some Players? Is it on GitHub? Heroku?
    4. 4. User Stories
    5. 5. (pivotal tracker)
    6. 6. In order to [value]As a [actor]I want [feature]
    7. 7. Players feature?
    8. 8. In order to know who is on a teamAs a league managerI want to see a list of players onthe team page
    9. 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. 10. CucumberFeature: 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"
    11. 11. User Storiesas Integration Tests
    12. 12. Setting up Cucumber1. Add `group :development, :test` to Gemfile2. Add ‘cucumber-rails’, ‘capybara’ and ‘database_cleaner’ in that group3. Run `bundle`4. Run `rails generate cucumber:install`5. `$EDITOR features/players.feature`
    13. 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
    14. 14. CODE(setting it up)
    15. 15. Running a scenario1. Put `@wip` above the scenario2. Run `rake cucumber:wip`
    16. 16. CODE(running it)
    17. 17. Debugging`Then show me the page`requires ‘launchy’ gem`Then debug` (debugger;1)requires ‘ruby-debug’ or ‘ruby-debug19’
    18. 18. CODE(debugging it)
    19. 19. Building data
    20. 20. `$EDITOR features/support/fixtures.rb`Before do  Team.create(:name => "Ballshevicks")end
    21. 21. • Any features/support/*.rb gets loaded• `Before` gets run before each Scenario
    22. 22. Other Data Options• Load test/fixtures/*.yml• Use the ‘fabrication’ object factory gem
    23. 23. CODE(giving it data)
    24. 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. 25. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular ExpressionWhen /^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. 26. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groupsWhen /^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. 27. Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groupsWhen /^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. 28. web_steps.rbGiven I am on the (rake routes) pageWhen 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”)
    29. 29. CODE(assigning teams?)
    30. 30. Unit testing
    31. 31. Use for direct testing of• Models (test/unit/*.rb)• Helpers (test/unit/helpers/*.rb)• Controllers (test/functional/*.rb)
    32. 32. Example: Player#last_nameclass PlayerTest < ActiveSupport::TestCase  test "parses out last name" do    trotter = Player.new(:name => "Trotter Cashion")    assert_equal "Cashion", trotter.last_name  endend (Test First! At least try.)
    33. 33. CODE(run and fix it)
    34. 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!

    ×