Class: Cuporter::FeatureParser::NodeParser

Inherits:
ParserBase
  • Object
show all
Defined in:
lib/cuporter/feature_parser/node_parser.rb

Constant Summary

Constants inherited from ParserBase

ParserBase::EXAMPLE_LINE, ParserBase::PY_STRING_LINE, ParserBase::TAG_LINE

Instance Attribute Summary

Attributes inherited from ParserBase

#lang, #root

Instance Method Summary collapse

Methods inherited from ParserBase

#clean_cuke_line, #file_relative_path, #handle_lines, #parse_feature

Constructor Details

#initialize(file, doc, filter) ⇒ NodeParser

Returns a new instance of NodeParser.



61
62
63
64
65
# File 'lib/cuporter/feature_parser/node_parser.rb', line 61

def initialize(file, doc, filter)
  super(file)
  @filter = filter
  @doc = doc
end

Instance Method Details

#close_scenario_outlineObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/cuporter/feature_parser/node_parser.rb', line 45

def close_scenario_outline
  if @scenario_outline
    if @example_set
      handle_example_set_line
      @example_set = nil
    end
    @feature.add_child(@scenario_outline) if @scenario_outline.has_children?
    @scenario_outline = nil
  end
end

#handle_eofObject



56
57
58
59
# File 'lib/cuporter/feature_parser/node_parser.rb', line 56

def handle_eof
  # EOF is the final way that we know we are finished with a "Scenario Outline"
  close_scenario_outline
end

#handle_example_set_lineObject



26
27
28
29
30
# File 'lib/cuporter/feature_parser/node_parser.rb', line 26

def handle_example_set_line
  if @filter.pass?(@feature.tags | @scenario_outline.tags | @example_set.tags)
    @scenario_outline.add_child @example_set
  end
end

#handle_scenario_line(sub_expression) ⇒ Object



14
15
16
17
18
# File 'lib/cuporter/feature_parser/node_parser.rb', line 14

def handle_scenario_line(sub_expression)
  if @filter.pass?(@current_tags | @feature.tags)
    @feature.add_child(Node.new_node(:Scenario, @doc, :cuke_name => sub_expression, :tags => @current_tags))
  end
end

#new_example_line(sub_expression) ⇒ Object



38
39
40
41
42
43
# File 'lib/cuporter/feature_parser/node_parser.rb', line 38

def new_example_line(sub_expression)
  example_type = :ExampleHeader
  # if the example set has a child already, then it must be the header
  example_type = :Example if @example_set.has_children?
  @example_set.add_child(Node.new_node(example_type, @doc, :cuke_name => sub_expression))
end

#new_example_set_node(sub_expression) ⇒ Object



32
33
34
35
36
# File 'lib/cuporter/feature_parser/node_parser.rb', line 32

def new_example_set_node(sub_expression)
  es = Node.new_node(:Examples, @doc, :cuke_name => sub_expression, :tags => @current_tags)
  es.filter = @filter
  es
end

#new_feature_node(sub_expression, file) ⇒ Object

sub_expression is the paren group in the regex, dereferenced with $1 in the caller



8
9
10
11
12
# File 'lib/cuporter/feature_parser/node_parser.rb', line 8

def new_feature_node(sub_expression, file)
  f = Node.new_node(:Feature, @doc, :cuke_name => sub_expression, :tags => @current_tags, :file_path => file)
  f.filter = @filter
  f
end

#new_scenario_outline_node(sub_expression) ⇒ Object



20
21
22
23
24
# File 'lib/cuporter/feature_parser/node_parser.rb', line 20

def new_scenario_outline_node(sub_expression)
  so = Node.new_node(:ScenarioOutline, @doc, :cuke_name => sub_expression, :tags => @current_tags)
  so.filter = @filter
  so
end