Class: Cuporter::TagNodesParser

Inherits:
FeatureParser show all
Defined in:
lib/cuporter/tag_nodes_parser.rb

Constant Summary

Constants inherited from FeatureParser

FeatureParser::EXAMPLE_LINE, FeatureParser::EXAMPLE_SET_LINE, FeatureParser::FEATURE_LINE, FeatureParser::PY_STRING_LINE, FeatureParser::SCENARIO_LINE, FeatureParser::SCENARIO_OUTLINE_LINE, FeatureParser::SCENARIO_SET_LINE, FeatureParser::TAG_LINE

Instance Attribute Summary

Attributes inherited from FeatureParser

#root

Instance Method Summary collapse

Methods inherited from FeatureParser

#clean_cuke_line, #file_relative_path, node, #parse_feature, tag_nodes

Constructor Details

#initialize(file, report, filter) ⇒ TagNodesParser

Returns a new instance of TagNodesParser.



86
87
88
89
90
91
# File 'lib/cuporter/tag_nodes_parser.rb', line 86

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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cuporter/tag_nodes_parser.rb', line 63

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



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

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



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

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

#handle_example_set_lineObject



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

def handle_example_set_line
end

#handle_scenario_line(sub_expression) ⇒ Object



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

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

#new_example_line(sub_expression) ⇒ Object



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

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



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

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



7
8
9
# File 'lib/cuporter/tag_nodes_parser.rb', line 7

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



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

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