Skip to content

Instantly share code, notes, and snippets.

@keeran
Created February 1, 2009 01:56
Show Gist options
  • Select an option

  • Save keeran/55748 to your computer and use it in GitHub Desktop.

Select an option

Save keeran/55748 to your computer and use it in GitHub Desktop.
# /features/authentication/homepage.feature
Feature: Homepage
Scenario Outline: Popular Activity
Given I am a new visitor
When I go to /notes
Then I should see an error message
# /features/steps/authentication/homepage_steps.rb
# (copied from login example)
Given /^I am a new visitor$/ do
# yay!
end
# /features/steps/webrat_steps.rb
# Commonly used webrat steps
# http://github.com/brynary/webrat
When /^I go to (.*)$/ do |path|
@response = visit path
end
When /^I press "(.*)"$/ do |button|
@response = click_button(button)
end
When /^I follow "(.*)"$/ do |link|
@response = click_link(link)
end
When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
@response = fill_in(field, :with => value)
end
When /^I select "(.*)" from "(.*)"$/ do |value, field|
@response = select(value, :from => field)
end
When /^I check "(.*)"$/ do |field|
@response = check(field)
end
When /^I uncheck "(.*)"$/ do |field|
@response = uncheck(field)
end
When /^I choose "(.*)"$/ do |field|
@response = choose(field)
end
When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
@response = attach_file(field, path)
end
# /features/steps/result_steps.rb
Then /^I should see "(.*)"$/ do |text|
response_body.to_s.should =~ /#{text}/m
end
Then /^I should not see "(.*)"$/ do |text|
response_body.to_s.should_not =~ /#{text}/m
end
Then /^I should see an? (\w+) message$/ do |message_type|
@response.should have_xpath("//*[@class='#{message_type}']")
end
Then /^the (.*) ?request should fail/ do |_|
@response.should_not be_successful
end
# output
$ rake features
(in /Users/keeran/dev/app)
Loading init file from /Users/keeran/dev/app/config/init.rb
Loading /Users/keeran/dev/app/config/environments/development.rb
Feature: Homepage # features/authentication/homepage.feature
Scenario Outline: Popular Activity # features/authentication/homepage.feature:2
Given I am a new visitor # features/authentication/homepage.feature:3
When I go to /notes # features/authentication/homepage.feature:4
Then I should see an error message# features/authentication/homepage.feature:5
Feature: Login # features/authentication/login.feature
To ensure the safety of the application
A regular user of the system
Must authenticate before using the app
Scenario Outline: Failed Login # features/authentication/login.feature:6
Given I am not authenticated # features/authentication/login.feature:7
When I go to /login # features/authentication/login.feature:8
And I fill in "login" with "<mail>" # features/authentication/login.feature:9
And I fill in "password" with "<password>" # features/authentication/login.feature:10
And I press "Log In" # features/authentication/login.feature:11
Then the login request should fail # features/authentication/login.feature:12
Then I should see an error message # features/authentication/login.feature:13
|mail |password |
|not_an_address|nil |
|not@not |123455 |
|[email protected] |wrong_paasword|
5 scenarios
21 steps passed
keeran@sylar ~/dev/app
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment