Sha256: da9f6511b08aff4fc33ce5cb1046a8b97f3614d50a0e1d007d71e18f0b48a0d3

Contents?: true

Size: 1.51 KB

Versions: 14

Compression:

Stored size: 1.51 KB

Contents

# File: macro-step-support.rb

require_relative "exceptions"
require_relative "macro-collection"

module Macros4Cuke # Module used as a namespace

# 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.
#
module MacroStepSupport

  # Callback invoked when a World object is extend(ed) with this module.
  def self.extended(world)
    # Add & initialize an instance variable for macro support.  
    MacroCollection::instance.init()
  end


public

  # Add a new macro.
  # Pre-condition: there is no existing macro with the same key.
  # [aPhrase] The text that is enclosed between the square brackets.
  # [aTemplate] A text that consists of a sequence of Cucumber steps.
  # These steps
  def add_macro(aPhrase, aTemplate)
    MacroCollection::instance.add_macro(aPhrase, aTemplate)
  end

  
  # Invoke a macro with given phrase and (optionally) a table of values
  # [aPhrase] an instance of the macro phrase.
  # [rawData] An Array of couples.
  # Each couple is of the form: argument name, a value.
  # Multiple rows with same argument name are acceptable.  
  def invoke_macro(aPhrase, rawData = nil)
    # Generate a text rendition of the step to be executed.
    rendered_steps = MacroCollection::instance.render_steps(aPhrase, rawData)
    
    # Execute the steps
    steps(rendered_steps)
  end

end # module

end # module

# End of file

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
macros4cuke-0.2.08 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.07 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.06 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.05 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.04 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.02 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.01 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.2.00 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.07 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.06 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.04 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.03 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.02 lib/macros4cuke/macro-step-support.rb
macros4cuke-0.1.00 lib/macros4cuke/macro-step-support.rb