class Gherkin::Listener::FormatterListener

Adapter from the “raw” Gherkin Listener API to the slightly more high-level Formatter API, which is easier to implement (less state to keep track of).

Public Class Methods

new(formatter) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 12
def initialize(formatter)
  @formatter = formatter
  @stash = Stash.new
  @current_builder = nil
end

Public Instance Methods

background(keyword, name, description, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 32
def background(keyword, name, description, line)
  @stash.feature_element(name) do |comments, tags, id|
    replay Formatter::Model::Background.new(comments, keyword, name, description, line)
  end
end
comment(value, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 18
def comment(value, line)
  @stash.comment Formatter::Model::Comment.new(value, line)
end
doc_string(content_type, value, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 72
def doc_string(content_type, value, line)
  @current_builder.doc_string(value, content_type, line)
end
eof() click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 76
def eof
  replay_step_or_examples
  @formatter.eof
end
examples(keyword, name, description, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 52
def examples(keyword, name, description, line)
  replay_step_or_examples
  @stash.examples(name) do |comments, tags, id|
    @current_builder = Formatter::Model::Examples::Builder.new(comments, tags, keyword, name, description, line, id)
  end
end
feature(keyword, name, description, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 26
def feature(keyword, name, description, line)
  @stash.feature(name) do |comments, tags, id|
    replay Formatter::Model::Feature.new(comments, tags, keyword, name, description, line, id)
  end
end
row(cells, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 66
def row(cells, line)
  @stash.row do |comments, id|
    @current_builder.row(comments, cells, line, id)
  end
end
scenario(keyword, name, description, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 38
def scenario(keyword, name, description, line)
  replay_step_or_examples
  @stash.feature_element(name) do |comments, tags, id|
    replay Formatter::Model::Scenario.new(comments, tags, keyword, name, description, line, id)
  end
end
scenario_outline(keyword, name, description, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 45
def scenario_outline(keyword, name, description, line)
  replay_step_or_examples
  @stash.feature_element(name) do |comments, tags, id|
    replay Formatter::Model::ScenarioOutline.new(comments, tags, keyword, name, description, line, id)
  end
end
step(keyword, name, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 59
def step(keyword, name, line)
  replay_step_or_examples
  @stash.step do |comments|
    @current_builder = Formatter::Model::Step::Builder.new(comments, keyword, name, line)
  end
end
syntax_error(state, ev, legal_events, uri, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 81
def syntax_error(state, ev, legal_events, uri, line)
  @formatter.syntax_error(state, ev, legal_events, uri, line)
end
tag(name, line) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 22
def tag(name, line)
  @stash.tag Formatter::Model::Tag.new(name, line)
end

Private Instance Methods

replay(element) click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 87
def replay(element)
  element.replay(@formatter)
end
replay_step_or_examples() click to toggle source
# File lib/gherkin/listener/formatter_listener.rb, line 143
def replay_step_or_examples
  return unless @current_builder
  replay(@current_builder)
  @current_builder = nil
end