This document discusses user stories and testing for a Rails application. It provides examples of writing user stories in a given/when/then format. It also covers setting up Cucumber for testing features, defining step implementations, building test data, and unit testing with Test::Unit. Web steps and examples of model and controller tests are shown. The homework mentioned is to write user stories for additional features and add a username/password authentication system.
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
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!