class Macros4Cuke::Formatter::ToGherkin
A macro-step formatter that outputs to the given IO the macro-steps from a macro collection into a Gherkin feature file.
Attributes
io[R]
The IO where the formatter's output will be written to.
step_count[R]
The number of macro-step encountered by the formatter.
Public Class Methods
new(anIO)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 19 def initialize(anIO) @io = anIO @step_count = 0 end
Public Instance Methods
implements()
click to toggle source
Tell which notifications this formatter subscribes to.
# File lib/macros4cuke/formatter/to-gherkin.rb, line 25 def implements() return %i[on_collection on_step on_step_end on_phrase on_source] end
on_collection(_, _)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 29 def on_collection(_, _) 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)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 48 def on_phrase(aLevel, aPhraseText, useTable) suffix = useTable ? ':' : '' io.print "#{indentation(aLevel)}Given I define the step " io.puts %("* I [#{aPhraseText}]#{suffix}" to mean:) end
on_source(aLevel, aSourceText)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 54 def on_source(aLevel, aSourceText) ljust = indentation(aLevel) triple_quotes = %(#{ljust}""") io.puts triple_quotes # Indent source text indented_text = aSourceText.gsub(/^/m, ljust.to_s) io.puts indented_text io.puts triple_quotes end
on_step(aLevel, _)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 39 def on_step(aLevel, _) @step_count += 1 io.puts "#{indentation(aLevel)}Scenario: Macro #{step_count}" end
on_step_end(_)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 44 def on_step_end(_) io.puts '' end
Private Instance Methods
indentation(aLevel)
click to toggle source
# File lib/macros4cuke/formatter/to-gherkin.rb, line 68 def indentation(aLevel) return ' ' * aLevel end