Module: Macros4Cuke::MacroStepSupport

Defined in:
lib/macros4cuke/macro-step-support.rb

Overview

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

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

Instance Method Summary collapse

Instance Method Details

#add_macro(aPhrase, aTemplate, useTable) ⇒ Object

Add a new macro. Pre-condition: there is no existing macro with the same key.

Parameters:

  • aPhrase (String)

    The text that is enclosed between the square brackets [...].

  • aTemplate (String)

    The text template that consists of a sequence of sub-steps.

  • useTable (boolean)

    A flag that indicates whether a table should be used to pass actual values.



23
24
25
# File 'lib/macros4cuke/macro-step-support.rb', line 23

def add_macro(aPhrase, aTemplate, useTable)
  MacroCollection::instance.add_macro(aPhrase, aTemplate, useTable)
end

#clear_macrosObject

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



43
44
45
# File 'lib/macros4cuke/macro-step-support.rb', line 43

def clear_macros()
  MacroCollection::instance.clear()
end

#invoke_macro(aPhraseInstance, rawData = nil) ⇒ Object

Invoke a macro with given phrase and (optionally) a table of values Multiple rows with same argument name are acceptable.

Parameters:

  • aPhraseInstance (String)

    an instance of the macro phrase. That is, the text between [...] and with zero or more actual values.

  • rawData (Array or nil) (defaults to: nil)

    An array of couples. Each couple is of the form: [macro argument name, a value].



32
33
34
35
36
37
38
# File 'lib/macros4cuke/macro-step-support.rb', line 32

def invoke_macro(aPhraseInstance, rawData = nil)
  # Generate a text rendition of the step to be executed.
  rendered_steps = MacroCollection::instance.render_steps(aPhraseInstance, rawData)
  
  # Let Cucumber execute the sub-steps
  steps(rendered_steps)
end