Created
August 30, 2012 17:59
-
-
Save leviwilson/3535625 to your computer and use it in GitHub Desktop.
Reusing background steps
This file contains hidden or 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
| class LoginPage | |
| include Gametel | |
| text(:username, :index => 0) | |
| text(:password, :index => 1) | |
| def login_successfully | |
| self.username = 'user' | |
| self.password = 'secret' | |
| on(LandingPage).should be_active | |
| end | |
| end | |
| Given /^I have logged in successfully$/ | |
| on(LoginPage).login_successfully | |
| end |
This file contains hidden or 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
| When I login with 'user' / 'secret' | |
| Then I am successfully logged in |
This file contains hidden or 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 /^I have logged in successfully$/ | |
| Given "I login with 'user' / 'secret' | |
| Then "I am successfully logged in" | |
| end |
This file contains hidden or 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
| Background: | |
| Given I have logged in successfully |
Author
General good rule of thumb is to strive to keep any technical stuff out of the cucumber steps.
Scenario: Axial Admin behavior
Given I am on sign in page
When I login as an "axial_admin" role
Then I should see the following links:
| Encounters |
| Runsheets |
| More |
| Sign Out |I could probably take the 'as an "X" role' and make that even more english-like: 'I login as an Axial Admin' and do some magic behind the scenes. Deeper in the step implementation, you can see some other styles of reuse:
Given /^I am logged in as an? "([^"]*)" role$/ do |role|
step %Q(I login as an "#{role}" role)
end
When /^I login as an? "([^"]*)" role$/ do |role|
login = "#{role}_user"
@user = FactoryGirl.create :user,
:id => 'user',
:login => "#{role}_user",
:role_string => role,
:confirmed_at => Time.now
step %Q(I login as "#{login}")
end
When /^I login as "([^"]*)"$/ do |login|
visit '/users/sign_in'
fill_in("user_login", :with => login)
fill_in("user_password", :with => "P@ssw0rd")
click_button "Sign In"
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right, that's why I added
So
rspecwill assert that we're on the landing page whereLandingPagelooks like