Class: Gherkin::Listener::FormatterListener

Inherits:
Object
  • Object
show all
Defined in:
lib/gherkin/listener/formatter_listener.rb

Overview

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).

Defined Under Namespace

Classes: Stash

Instance Method Summary collapse

Constructor Details

#initialize(formatter) ⇒ FormatterListener

Returns a new instance of FormatterListener.



12
13
14
15
# File 'lib/gherkin/listener/formatter_listener.rb', line 12

def initialize(formatter)
  @formatter = formatter
  @stash = Stash.new
end

Instance Method Details

#background(keyword, name, description, line) ⇒ Object



31
32
33
34
35
# File 'lib/gherkin/listener/formatter_listener.rb', line 31

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) ⇒ Object



17
18
19
# File 'lib/gherkin/listener/formatter_listener.rb', line 17

def comment(value, line)
  @stash.comment Formatter::Model::Comment.new(value, line)
end

#doc_string(content_type, value, line) ⇒ Object



71
72
73
# File 'lib/gherkin/listener/formatter_listener.rb', line 71

def doc_string(content_type, value, line)
  @current_builder.doc_string(value, content_type, line)
end

#eofObject



75
76
77
78
# File 'lib/gherkin/listener/formatter_listener.rb', line 75

def eof
  replay_step_or_examples
  @formatter.eof
end

#examples(keyword, name, description, line) ⇒ Object



51
52
53
54
55
56
# File 'lib/gherkin/listener/formatter_listener.rb', line 51

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) ⇒ Object



25
26
27
28
29
# File 'lib/gherkin/listener/formatter_listener.rb', line 25

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) ⇒ Object



65
66
67
68
69
# File 'lib/gherkin/listener/formatter_listener.rb', line 65

def row(cells, line)
  @stash.basic_statement do |comments, id|
    @current_builder.row(comments, cells, line, id)
  end
end

#scenario(keyword, name, description, line) ⇒ Object



37
38
39
40
41
42
# File 'lib/gherkin/listener/formatter_listener.rb', line 37

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) ⇒ Object



44
45
46
47
48
49
# File 'lib/gherkin/listener/formatter_listener.rb', line 44

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) ⇒ Object



58
59
60
61
62
63
# File 'lib/gherkin/listener/formatter_listener.rb', line 58

def step(keyword, name, line)
  replay_step_or_examples
  @stash.basic_statement do |comments, id|
    @current_builder = Formatter::Model::Step::Builder.new(comments, keyword, name, line)
  end
end

#syntax_error(state, ev, legal_events, uri, line) ⇒ Object



80
81
82
# File 'lib/gherkin/listener/formatter_listener.rb', line 80

def syntax_error(state, ev, legal_events, uri, line)
  @formatter.syntax_error(state, ev, legal_events, uri, line)
end

#tag(name, line) ⇒ Object



21
22
23
# File 'lib/gherkin/listener/formatter_listener.rb', line 21

def tag(name, line)
  @stash.tag Formatter::Model::Tag.new(name, line)
end