Class: Macros4Cuke::Formatter::ToGherkin
- Inherits:
-
Object
- Object
- Macros4Cuke::Formatter::ToGherkin
- Defined in:
- lib/macros4cuke/formatter/to-gherkin.rb
Overview
A macro-step formatter that outputs to the given IO the macro-steps from a macro collection into a Gherkin feature file.
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
The IO where the formatter's output will be written to.
-
#step_count ⇒ Object
readonly
The number of macro-step encountered by the formatter.
Instance Method Summary collapse
-
#implements ⇒ Object
Tell which notifications this formatter subscribes to.
-
#initialize(anIO) ⇒ ToGherkin
constructor
A new instance of ToGherkin.
- #on_collection(aLevel, aMacroCollection) ⇒ Object
- #on_phrase(aLevel, aPhraseText, useTable) ⇒ Object
- #on_source(aLevel, aSourceText) ⇒ Object
- #on_step(aLevel, aMacroStep) ⇒ Object
- #on_step_end(aLevel) ⇒ Object
Constructor Details
#initialize(anIO) ⇒ ToGherkin
Returns a new instance of ToGherkin.
19 20 21 22 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 19 def initialize(anIO) @io = anIO @step_count = 0 end |
Instance Attribute Details
#io ⇒ Object (readonly)
The IO where the formatter's output will be written to.
14 15 16 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 14 def io @io end |
#step_count ⇒ Object (readonly)
The number of macro-step encountered by the formatter.
17 18 19 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 17 def step_count @step_count end |
Instance Method Details
#implements ⇒ Object
Tell which notifications this formatter subscribes to.
27 28 29 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 27 def implements() return [:on_collection, :on_step, :on_step_end, :on_phrase, :on_source] end |
#on_collection(aLevel, aMacroCollection) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 31 def on_collection(aLevel, aMacroCollection) io.print "# Feature file generated by Macro4Cuke #{Macros4Cuke::Version}" io.puts " on #{Time.now.strftime('%d/%m/%Y %H:%M:%S')}" io.puts '' io.puts 'Feature: the set of macro-step definitions' io.puts "#{indentation(1)}As a feature file writer" io.puts "#{indentation(1)}So that I write higher-level steps" io.puts '' end |
#on_phrase(aLevel, aPhraseText, useTable) ⇒ Object
51 52 53 54 55 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 51 def on_phrase(aLevel, aPhraseText, useTable) suffix = useTable ? ':' : '' io.print "#{indentation(aLevel)}Given I define the step " io.puts %Q|"* I [#{aPhraseText}]#{suffix}" to mean:| end |
#on_source(aLevel, aSourceText) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 57 def on_source(aLevel, aSourceText) ljust = indentation(aLevel) triple_quotes = %Q|#{ljust}"""| io.puts triple_quotes # Indent source text indented_text = aSourceText.gsub(/^/m, "#{ljust}") io.puts indented_text io.puts triple_quotes end |
#on_step(aLevel, aMacroStep) ⇒ Object
41 42 43 44 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 41 def on_step(aLevel, aMacroStep) @step_count += 1 io.puts "#{indentation(aLevel)}Scenario: Macro #{step_count}" end |
#on_step_end(aLevel) ⇒ Object
46 47 48 |
# File 'lib/macros4cuke/formatter/to-gherkin.rb', line 46 def on_step_end(aLevel) io.puts '' end |