bjeanes (owner)

Forks

Revisions

gist: 221223 Download_button fork
public
Public Clone URL: git://gist.github.com/221223.git
Embed All Files: show embed
README #
1
2
3
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...
cucumber_helper.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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)
EXAMPLE USAGE.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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