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)
-
- (Object) feature
readonly
Returns the value of attribute feature.
Instance Method Summary (collapse)
-
- (Visitor) initialize
constructor
A new instance of Visitor.
- - (Object) visit(ast)
-
- (Object) visit_Background(node)
Iterates over the steps.
-
- (Object) visit_Feature(node)
Sets the feature name and iterates over the feature scenarios.
-
- (Object) visit_Scenario(node)
Sets the scenario name and iterates over the steps.
-
- (Object) visit_Step(node)
Adds the step to the current scenario.
-
- (Object) visit_Tag(node)
Adds the tag to the current scenario.
Constructor Details
- (Visitor) initialize
A new instance of Visitor
19 20 21 |
# File 'lib/spinach/parser/visitor.rb', line 19 def initialize @feature = Feature.new end |
Instance Attribute Details
- (Object) feature (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
- (Object) visit(ast)
27 28 29 30 |
# File 'lib/spinach/parser/visitor.rb', line 27 def visit(ast) ast.accept self @feature end |
- (Object) visit_Background(node)
Iterates over the steps.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/spinach/parser/visitor.rb', line 55 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 |
- (Object) visit_Feature(node)
Sets the feature name and iterates over the feature scenarios.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/spinach/parser/visitor.rb', line 38 def visit_Feature(node) @feature.name = node.name 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 |
- (Object) visit_Scenario(node)
Sets the scenario name and iterates over the steps.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/spinach/parser/visitor.rb', line 72 def visit_Scenario(node) scenario = Scenario.new(@feature) scenario.name = node.name scenario.line = node.line @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 |
- (Object) visit_Step(node)
Adds the step to the current scenario.
104 105 106 107 108 109 110 111 |
# File 'lib/spinach/parser/visitor.rb', line 104 def visit_Step(node) step = Step.new(@current_scenario) step.name = node.name step.line = node.line step.keyword = node.keyword @current_step_set.steps << step end |
- (Object) visit_Tag(node)
Adds the tag to the current scenario.
94 95 96 |
# File 'lib/spinach/parser/visitor.rb', line 94 def visit_Tag(node) @current_tag_set. << node.name end |