Class: Cucumber::Parser::GherkinBuilder

Inherits:
Object
  • Object
show all
Includes:
Gherkin::Rubify
Defined in:
lib/cucumber/parser/gherkin_builder.rb

Overview

This class conforms to the Gherkin event API and builds the “legacy” AST. It will be replaced later when we have a new “clean” AST.

Instance Method Summary collapse

Instance Method Details

#astObject



12
13
14
# File 'lib/cucumber/parser/gherkin_builder.rb', line 12

def ast
  @feature || @multiline_arg
end

#background(background) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cucumber/parser/gherkin_builder.rb', line 29

def background(background)
  @background = Ast::Background.new(
    Ast::Comment.new(background.comments.map{|comment| comment.value}.join("\n")), 
    background.line, 
    background.keyword, 
    legacy_name_for(background.name, background.description), 
    steps=[]
  )
  @feature.background = @background
  @background.feature = @feature
  @step_container = @background
  @background.gherkin_statement(background)
end

#eofObject



103
104
# File 'lib/cucumber/parser/gherkin_builder.rb', line 103

def eof
end

#examples(examples) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# File 'lib/cucumber/parser/gherkin_builder.rb', line 79

def examples(examples)
  examples_fields = [
    Ast::Comment.new(examples.comments.map{|comment| comment.value}.join("\n")), 
    examples.line, 
    examples.keyword, 
    legacy_name_for(examples.name, examples.description), 
    matrix(examples.rows)
  ]
  @step_container.add_examples(examples_fields, examples)
end

#feature(feature) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cucumber/parser/gherkin_builder.rb', line 16

def feature(feature)
  @feature = Ast::Feature.new(
    nil, 
    Ast::Comment.new(feature.comments.map{|comment| comment.value}.join("\n")), 
    Ast::Tags.new(nil, feature.tags.map{|tag| tag.name}),
    feature.keyword,
    legacy_name_for(feature.name, feature.description),
    []
  )
  @feature.gherkin_statement(feature)
  @feature
end

#scenario(statement) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cucumber/parser/gherkin_builder.rb', line 43

def scenario(statement)
  scenario = Ast::Scenario.new(
    @background, 
    Ast::Comment.new(statement.comments.map{|comment| comment.value}.join("\n")), 
    Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}), 
    statement.line, 
    statement.keyword, 
    legacy_name_for(statement.name, statement.description), 
    steps=[]
  )
  @feature.add_feature_element(scenario)
  @background.feature_elements << scenario if @background
  @step_container = scenario
  scenario.gherkin_statement(statement)
end

#scenario_outline(statement) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cucumber/parser/gherkin_builder.rb', line 59

def scenario_outline(statement)
  scenario_outline = Ast::ScenarioOutline.new(
    @background, 
    Ast::Comment.new(statement.comments.map{|comment| comment.value}.join("\n")), 
    Ast::Tags.new(nil, statement.tags.map{|tag| tag.name}), 
    statement.line, 
    statement.keyword, 
    legacy_name_for(statement.name, statement.description), 
    steps=[],
    example_sections=[]
  )
  @feature.add_feature_element(scenario_outline)
  if @background
    @background = @background.dup
    @background.feature_elements << scenario_outline
  end
  @step_container = scenario_outline
  scenario_outline.gherkin_statement(statement)
end

#step(step) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cucumber/parser/gherkin_builder.rb', line 90

def step(step)
  @table_owner = Ast::Step.new(step.line, step.keyword, step.name)
  @table_owner.gherkin_statement(step)
  multiline_arg = rubify(step.multiline_arg)
  case(multiline_arg)
  when Gherkin::Formatter::Model::PyString
    @table_owner.multiline_arg = Ast::PyString.new(multiline_arg.value)
  when Array
    @table_owner.multiline_arg = Ast::Table.new(matrix(multiline_arg))
  end
  @step_container.add_step(@table_owner)
end

#syntax_error(state, event, legal_events, line) ⇒ Object



106
107
108
# File 'lib/cucumber/parser/gherkin_builder.rb', line 106

def syntax_error(state, event, legal_events, line)
  # raise "SYNTAX ERROR"
end