Skip to content

Instantly share code, notes, and snippets.

@bjeanes
Created October 29, 2009 06:57
Show Gist options
  • Save bjeanes/221223 to your computer and use it in GitHub Desktop.
Save bjeanes/221223 to your computer and use it in GitHub Desktop.
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...
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)
# 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