Class: Cuporter::FeatureParser::TagNodesParser

Inherits:
ParserBase
  • Object
show all
Defined in:
lib/cuporter/feature_parser/tag_nodes_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, report, filter) ⇒ TagNodesParser

Returns a new instance of TagNodesParser.



103
104
105
106
107
108
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 103

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

Instance Method Details

#add_example(tag, feature, scenario_outline, example_set, example) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 80

def add_example(tag, feature, scenario_outline, example_set, example)
  unless ( t = @report.tag_node(tag))
    t = @report.add_child(Node.new_node(:Tag, @doc, 'cuke_name' => tag))
  end
  unless ( f = t.feature_node(feature) )
    f = t.add_child(Node.new_node(:Feature, @doc, feature))
  end
  unless ( so = f.scenario_outline_node(scenario_outline) )
    so = f.add_child(Node.new_node(:ScenarioOutline, @doc, scenario_outline))
  end

  # The first Example is an ExampleHeader, which does not get counted or
  # numbered.  If the ExampleSet is new, it has no children, and therefore
  # this is the first and should be an ExampleHeader.
  example_type = :Example
  unless ( es = so.example_set_node(example_set) )
    es = so.add_child(Node.new_node(:Examples, @doc, example_set))
    example_type = :ExampleHeader
  end
  es.add_child(Node.new_node(example_type, @doc, example))
end

#add_scenario(tag, feature, scenario) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 70

def add_scenario(tag, feature, scenario)
  unless ( t = @report.tag_node(tag))
    t = @report.add_child(Node.new_node(:tag, @doc, 'cuke_name' => tag))
  end
  unless ( f = t.feature_node(feature) )
    f = t.add_child(Node.new_node(:Feature, @doc, feature))
  end
  f.add_child(Node.new_node(:Scenario, @doc, scenario))
end

#close_scenario_outlineObject



62
63
64
65
66
67
68
69
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 62

def close_scenario_outline
  if @scenario_outline
    if @example_set
      @example_set = nil
    end
    @scenario_outline = nil
  end
end

#handle_eofObject



47
48
49
50
51
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 47

def handle_eof
  # EOF is the final way that we know we are finished with a "Scenario Outline"
  close_scenario_outline
  handle_tagless_feature if @filter.empty?
end

#handle_example_set_lineObject



27
28
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 27

def handle_example_set_line
end

#handle_scenario_line(sub_expression) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 12

def handle_scenario_line(sub_expression)
  if @filter.pass?(@feature[:tags] | @current_tags)
    s = {:cuke_name => sub_expression, :tags => @current_tags}

    (@feature[:tags] | s[:tags]).each do |tag|
      next unless @filter.pass?([tag])
      add_scenario(tag, @feature, s)
    end
  end
end

#handle_tagless_featureObject



53
54
55
56
57
58
59
60
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 53

def handle_tagless_feature
  if @feature && !@report.feature_node(@feature)
    unless ( t = @report.tag_node(@report.class::TAGLESS))
      t = @report.add_child(Node.new_node(:tag, @doc, 'cuke_name' => @report.class::TAGLESS))
    end
    t.add_child(Node.new_node(:Feature, @doc, @feature))
  end
end

#new_example_line(sub_expression) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 34

def new_example_line(sub_expression)
  context_tags = (@feature[:tags] | @scenario_outline[:tags] | @example_set[:tags])
  if @filter.pass?(context_tags)
    e = {:cuke_name => sub_expression}

    context_tags.each do |tag|
      next unless @filter.pass?([tag])
      add_example(tag, @feature, @scenario_outline, @example_set, e)
    end
  end
end

#new_example_set_node(sub_expression) ⇒ Object



30
31
32
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 30

def new_example_set_node(sub_expression)
  {:cuke_name => sub_expression.to_s.strip, :tags => @current_tags}
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
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 8

def new_feature_node(sub_expression, file)
  {:cuke_name => sub_expression, :tags => @current_tags, :file_path => file}
end

#new_scenario_outline_node(sub_expression) ⇒ Object



23
24
25
# File 'lib/cuporter/feature_parser/tag_nodes_parser.rb', line 23

def new_scenario_outline_node(sub_expression)
  {:cuke_name => sub_expression, :tags => @current_tags}
end