Sha256: fd8e21d01a6d33bc4c93694ecafda7843831fb2ba9a525d4d851efa4dd6fb122

Contents?: true

Size: 1.63 KB

Versions: 16

Compression:

Stored size: 1.63 KB

Contents

# encoding: utf-8
# 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"
#  """
# The regexp has two capturing group: one for the phrase, 
# a second for the terminating colon (:)
Given(/^I define the step "(?:Given|When|Then|\*) I \[((?:[^\\\]]|\\.)+)\](:?)" to mean:$/) do |macro_phrase, colon_capture, template|
  use_table = (colon_capture == ':')
  add_macro(macro_phrase, template, use_table)
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 data 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 Macros4Cuke::DataTableNotFound.new(macro_phrase)
  end

  # This will call the macro with the given phrase.
  # The second argument consists of an array 
  # with couples of the kind: [argument name, actual value]
  invoke_macro(macro_phrase, table_argument.raw)
end


# End of file

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
macros4cuke-0.3.32 lib/macro_steps.rb
macros4cuke-0.3.30 lib/macro_steps.rb
macros4cuke-0.3.29 lib/macro_steps.rb
macros4cuke-0.3.28 lib/macro_steps.rb
macros4cuke-0.3.27 lib/macro_steps.rb
macros4cuke-0.3.26 lib/macro_steps.rb
macros4cuke-0.3.25 lib/macro_steps.rb
macros4cuke-0.3.24 lib/macro_steps.rb
macros4cuke-0.3.23 lib/macro_steps.rb
macros4cuke-0.3.22 lib/macro_steps.rb
macros4cuke-0.3.21 lib/macro_steps.rb
macros4cuke-0.3.20 lib/macro_steps.rb
macros4cuke-0.3.19 lib/macro_steps.rb
macros4cuke-0.3.18 lib/macro_steps.rb
macros4cuke-0.3.17 lib/macro_steps.rb
macros4cuke-0.3.16 lib/macro_steps.rb