Sha256: f9e1728b932016ae7538de00a322dcb35fc4a7837849fee9aa46f746346beebb

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# File: macro_steps.rb
# Purpose: step definitions that help to build macro-steps (i.e. a step that is equivalent to a sequence of steps)



# This step is used to define a macro-step
# Example:
#  Given I define the step "When I [log in as {{userid}}]" to mean:
#  """
#  Given I landed in the homepage
#  When I click "Sign in"
#  And I fill in "Username" with "{{userid}}"
#  And I fill in "Password" with "unguessable"
#  And I click "Submit"
#  """
Given(/^I define the step "(?:Given|When|Then) I \[((?:[^\\\]]|\\.)+\]:?)" to mean:$/) do |macro_phrase, template|
  add_macro(macro_phrase, template)
end

# This step is used to invoke a simple macro-step
# Example:
#  When I [log in as "guest"]
#
When(/^I \[((?:[^\\\]]|\\.)+\])$/) do |macro_phrase|
  invoke_macro(macro_phrase)  # This will call the macro with the given phrase
end


# This step is used to invoke a macro-step with a table argument.
# Example:
#  When I [enter my credentials as]:
#  |userid  |guest      |
#  |password|unguessable|
When(/^I \[([^\]]+\]:)$/) do |macro_phrase, table_argument|
  # Ensure that the second argument is of the correct type
  unless table_argument.kind_of?(Cucumber::Ast::Table)
     raise StandardError, "This step must have a data table as an argument."
  end
  
  # This will call the macro with the given phrase.
  # The second argument consists of a hash with pairs of the kind: argument name => actual value
  invoke_macro(macro_phrase, table_argument.rows_hash())
end


# End of file

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
macros4cuke-0.2.08 lib/macro_steps.rb
macros4cuke-0.2.07 lib/macro_steps.rb
macros4cuke-0.2.06 lib/macro_steps.rb
macros4cuke-0.2.05 lib/macro_steps.rb