Created
October 29, 2009 06:57
-
-
Save bjeanes/221223 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
See the EXAMPLE_USAGE. | |
I will be adding this to a repo with its tests a bit later and then perhaps forking Cucumber and adding it in and sending a pull request. Might rename the method to RunSteps() though... |
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 CucumberHelper | |
def Cucumber(steps) | |
steps.strip.split(/(?=^\s*(?:When|Then|Given|And|But))/).map { |step| step.strip }.each do |step| | |
output = step.match(/^\s*(When|Then|Given|And|But) ([^\n]+)(\n.*)?$/m) | |
action, step, table_or_string = output[1], output[2], output[3] | |
table_or_string = table(table_or_string) if table_or_string.to_s.strip[0..1] == "|" | |
args = [step, table_or_string].compact | |
send(action, *args) | |
end | |
end | |
end | |
World(CucumberHelper) |
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
# Allows you to do (1) instead of (2) | |
# 1 | |
Given /^I sign up as a staff member with login "([^\"]*)"$/ do |login| | |
Cucumber(%Q{ | |
When I go to the sign up page | |
And I fill in "Username" with "#{login}" | |
And I fill in "Password" with "password" | |
And I fill in "Password again" with "password" | |
And I fill in "Email" with "#{login}@domain.com" | |
And I check "I am a staff member" | |
And I press "Sign Up" | |
} | |
end | |
# 2 | |
Given /^I sign up as a staff member with login "([^\"]*)"$/ do |login| | |
When %Q{I go to the sign up page} | |
And %Q{I fill in "Username" with "#{login}"} | |
And %Q{I fill in "Password" with "password"} | |
And %Q{I fill in "Password again" with "password"} | |
And %Q{I fill in "Email" with "#{login}@domain.com"} | |
And %Q{I check "I am a staff member"} | |
And %Q{I press "Sign Up"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment