Class: Spinach::Parser::Visitor
- Inherits:
-
Object
- Object
- Spinach::Parser::Visitor
- Defined in:
- lib/spinach/parser/visitor.rb
Overview
The Spinach Visitor traverses the output AST from the GherkinRuby parser and populates its Feature with all the scenarios, tags, steps, etc.
Instance Attribute Summary collapse
-
#feature ⇒ Object
readonly
Returns the value of attribute feature.
Instance Method Summary collapse
-
#initialize ⇒ Visitor
constructor
A new instance of Visitor.
- #visit(ast) ⇒ Object
-
#visit_Background(node) ⇒ Object
Iterates over the steps.
-
#visit_Feature(node) ⇒ Object
Sets the feature name and iterates over the feature scenarios.
-
#visit_Scenario(node) ⇒ Object
Sets the scenario name and iterates over the steps.
-
#visit_Step(node) ⇒ Object
Adds the step to the current scenario.
-
#visit_Tag(node) ⇒ Object
Adds the tag to the current scenario.
Constructor Details
Instance Attribute Details
#feature ⇒ Object (readonly)
Returns the value of attribute feature.
13 14 15 |
# File 'lib/spinach/parser/visitor.rb', line 13 def feature @feature end |
Instance Method Details
#visit(ast) ⇒ Object
27 28 29 30 31 |
# File 'lib/spinach/parser/visitor.rb', line 27 def visit(ast) ast.accept(self) @feature end |
#visit_Background(node) ⇒ Object
Iterates over the steps.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/spinach/parser/visitor.rb', line 58 def visit_Background(node) background = Background.new(@feature) background.line = node.line @current_step_set = background node.steps.each { |step| step.accept(self) } @current_step_set = nil @feature.background = background end |
#visit_Feature(node) ⇒ Object
Sets the feature name and iterates over the feature scenarios.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spinach/parser/visitor.rb', line 39 def visit_Feature(node) @feature.name = node.name @feature.description = node.description node.background.accept(self) if node.background @current_tag_set = @feature node..each { |tag| tag.accept(self) } @current_tag_set = nil node.scenarios.each { |scenario| scenario.accept(self) } end |
#visit_Scenario(node) ⇒ Object
Sets the scenario name and iterates over the steps.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/spinach/parser/visitor.rb', line 75 def visit_Scenario(node) scenario = Scenario.new(@feature) scenario.name = node.name scenario.lines = [ node.line, *node.steps.map(&:line) ].uniq.sort @current_tag_set = scenario node..each { |tag| tag.accept(self) } @current_tag_set = nil @current_step_set = scenario node.steps.each { |step| step.accept(self) } @current_step_set = nil @feature.scenarios << scenario end |
#visit_Step(node) ⇒ Object
Adds the step to the current scenario.
110 111 112 113 114 115 116 117 |
# File 'lib/spinach/parser/visitor.rb', line 110 def visit_Step(node) step = Step.new(@current_step_set) step.name = node.name step.line = node.line step.keyword = node.keyword @current_step_set.steps << step end |
#visit_Tag(node) ⇒ Object
Adds the tag to the current scenario.
100 101 102 |
# File 'lib/spinach/parser/visitor.rb', line 100 def visit_Tag(node) @current_tag_set. << node.name end |