Class: Cuporter::FeatureParser

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

Direct Known Subclasses

NameListParser, TagListParser

Constant Summary collapse

FEATURE_LINE =
/^\s*(Feature:[^#]+)/
TAG_LINE =
/^\s*(@\w.+)/
SCENARIO_LINE =
/^\s*(Scenario:[^#]+)$/
SCENARIO_OUTLINE_LINE =
/^\s*(Scenario Outline:[^#]+)$/
SCENARIO_SET_LINE =
/^\s*(Scenarios:[^#]*)$/
EXAMPLE_SET_LINE =
/^\s*(Examples:[^#]*)$/
EXAMPLE_LINE =
/^\s*(\|.*\|)\s*$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ FeatureParser

Returns a new instance of FeatureParser.



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

def initialize(file)
  @file = file
  @current_tags = []
  @lines = File.read(@file).split(/\n/)
end

Class Method Details

.name_list(file, filter) ⇒ Object



17
18
19
# File 'lib/cuporter/feature_parser.rb', line 17

def self.name_list(file, filter)
  NameListParser.new(file, filter).parse_feature
end

.tag_list(file) ⇒ Object



13
14
15
# File 'lib/cuporter/feature_parser.rb', line 13

def self.tag_list(file)
  TagListParser.new(file).parse_feature
end

Instance Method Details

#parse_featureObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cuporter/feature_parser.rb', line 27

def parse_feature
  @lines.each do |line|
    case line
    when FeatureParser::TAG_LINE
      # may be more than one tag line
      @current_tags |= $1.strip.split(/\s+/)
    when FeatureParser::FEATURE_LINE
      @feature = new_feature_node($1)
      @feature.file = @file.sub(/^.*features\//,"features/")
      @current_tags = []
    when FeatureParser::SCENARIO_LINE
      # How do we know when we have read all the lines from a "Scenario Outline:"?
      # One way is when we encounter a "Scenario:"
      close_scenario_outline

      handle_scenario_line($1)
      @current_tags = []
    when FeatureParser::SCENARIO_OUTLINE_LINE
      # ... another is when we hit a subsequent "Scenario Outline:"
      close_scenario_outline

      @scenario_outline  = new_scenario_outline_node($1)
      @current_tags = []
    when FeatureParser::EXAMPLE_SET_LINE, FeatureParser::SCENARIO_SET_LINE
      handle_example_set_line if @example_set

      @example_set = new_example_set_node($1)
      @current_tags = []
    when @example_set && FeatureParser::EXAMPLE_LINE
      @example_set.add_child(Node.new($1))
    end
  end

  # EOF is the final way that we know we are finished with a "Scenario Outline"
  close_scenario_outline
  return @feature
end