module Macros4Cuke::MacroStepSupport

Mix-in module that should be extending World objects in Cucumber. Synopsis (in env.rb):

require 'macros4cuke'
...
# Extend the world object with this module.
World(Macros4Cuke::MacroStepSupport)

Attributes

substeps_trace[R]

The substeps being executed in the scenario represented as text.

Public Instance Methods

add_macro(aPhrase, aTemplate, useTable) click to toggle source

Add a new macro. Pre-condition: there is no existing macro with the same key. @param aPhrase [String] The text that is enclosed between the square brackets […]. @param aTemplate [String] The text template that consists of a sequence of sub-steps. @param useTable [boolean] A flag that indicates whether a table should be used to pass actual values.

# File lib/macros4cuke/macro-step-support.rb, line 29
def add_macro(aPhrase, aTemplate, useTable)
  MacroCollection.instance.add_macro(aPhrase, aTemplate, useTable)
end
clear_macros() click to toggle source

Clear (remove) all the macro-step definitions. After this, we are in the same situation when no macro-step was ever defined.

# File lib/macros4cuke/macro-step-support.rb, line 56
def clear_macros()
  MacroCollection.instance.clear
end
invoke_macro(aPhraseInstance, rawData = nil) click to toggle source

Invoke a macro with given phrase and (optionally) a table of values @param aPhraseInstance [String] an instance of the macro phrase. That is, the text between […] and with zero or more actual values. @param rawData [Array or nil] An Array with couples of the form: [macro argument name, a value]. Multiple rows with same argument name are acceptable.

# File lib/macros4cuke/macro-step-support.rb, line 39
def invoke_macro(aPhraseInstance, rawData = nil)
  # Generate a text rendition of the step to be executed.
  collection = MacroCollection.instance
  rendered_steps = collection.render_steps(aPhraseInstance, rawData)
  
  # Keep track of the sub-steps to execute
  @substeps_trace = +'' if @substeps_trace.nil?
  @substeps_trace << rendered_steps
  

  # Let Cucumber execute the sub-steps
  steps(rendered_steps)
end