Class: Macros4Cuke::MacroCollection
- Inherits:
-
Object
- Object
- Macros4Cuke::MacroCollection
- Includes:
- Singleton
- Defined in:
- lib/macros4cuke/macro-collection.rb
Overview
This is a singleton class: there is only one macro collection object.
Represents a container of macros.
It gathers all the macros encountered by Cucumber while "executing"
the feature files.
Instance Attribute Summary collapse
-
#macro_steps. ⇒ Object
readonly
A Hash with pairs of the form: macro key => MacroStep object.
Instance Method Summary collapse
-
#add_macro(aPhrase, aTemplate, useTable) ⇒ Object
Add a new macro.
-
#clear ⇒ Object
Clear/remove all macro definitions from the collection.
-
#macro_steps ⇒ Object
Read accessor for the @macro_steps attribute.
-
#render_steps(aPhrase, rawData = nil) ⇒ String
Render the steps associated to the macro with given phrase and (optionally) given a table of values.
Instance Attribute Details
#macro_steps. ⇒ Object (readonly)
A Hash with pairs of the form: macro key => MacroStep object
|
# File 'lib/macros4cuke/macro-collection.rb', line 16
|
Instance Method Details
#add_macro(aPhrase, aTemplate, useTable) ⇒ Object
Add a new macro. Pre-condition: there is no existing macro with the same key. the square brackets. used to pass actual values.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/macros4cuke/macro-collection.rb', line 29 def add_macro(aPhrase, aTemplate, useTable) new_macro = MacroStep.new(aPhrase, aTemplate, useTable) # Prevent collision of macros (macros with same phrase). # This can occur if a macro was defined in a background section. # An exception is raised if the phrase syntax of both macros are the fail(DuplicateMacroError, aPhrase) if find_macro(aPhrase, useTable) macro_steps[new_macro.key] = new_macro end |
#clear ⇒ Object
Clear/remove all macro definitions from the collection. Post-condition: we are back to the same situation as no macro was ever defined.
61 62 63 |
# File 'lib/macros4cuke/macro-collection.rb', line 61 def clear() macro_steps.clear end |
#macro_steps ⇒ Object
Read accessor for the @macro_steps attribute.
67 68 69 70 |
# File 'lib/macros4cuke/macro-collection.rb', line 67 def macro_steps() @macro_steps ||= {} return @macro_steps end |
#render_steps(aPhrase, rawData = nil) ⇒ String
Render the steps associated to the macro with given phrase and (optionally) given a table of values. Return the rendered steps as a text. [macro argument name, a value]. Multiple rows with same argument name are acceptable.
48 49 50 51 52 53 54 55 |
# File 'lib/macros4cuke/macro-collection.rb', line 48 def render_steps(aPhrase, rawData = nil) use_table = !rawData.nil? macro = find_macro(aPhrase, use_table) fail(UnknownMacroError, aPhrase) if macro.nil? # Render the steps return macro.(aPhrase, rawData) end |