Created
October 8, 2011 22:18
-
-
Save prathe/1272973 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: User login | |
Scenario: User is greeted upon login | |
Given a user with an account | |
When he logs in | |
Then he should be greeted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UserLoginSteps | |
def create_user(user = FactoryGirl.build(:user)) | |
user.save_without_session_maintenance | |
user | |
end | |
def login(user) | |
visit login_path | |
fill_in 'Email', :with => user.email | |
fill_in 'Password', :with => user.password | |
click_on 'Log in' | |
end | |
end | |
World UserLoginSteps | |
RSpec::Matchers.define :be_greeted do | |
match do |user| | |
greeting_message = "Welcome, #{user.name}" | |
page.has_content? greeting_message | |
end | |
failure_message_for_should do | |
"expected the user to see a greeting message" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given /^a user with an account$/ do | |
@user = create_user | |
end | |
When /^he logs in$/ do | |
login @user | |
end | |
Then /^he should be greeted$/ do | |
@user.should be_greeted | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: User logout | |
Scenario: User is kicked off from his account upon logout | |
Given a logged in user | |
When he logs out | |
Then he should be kicked off from his account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module UserLogoutSteps | |
def logout(user) | |
visit logout_path | |
end | |
end | |
World UserLogoutSteps | |
RSpec::Matchers.define :be_kicked_off do | |
match do |user| | |
!UserSession.find && current_path != account_path | |
end | |
failure_message_for_should do |user| | |
"expected the user to be kicked off from his account" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given /^a logged in user$/ do | |
@user = create_user | |
login @user | |
end | |
When /^he logs out$/ do | |
logout @user | |
end | |
Then /^he should be kicked off from his account$/ do | |
@user.should be_kicked_off | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that these scenarios are declarative and not imperative.