Class: Cuporter::FeatureParser
- Inherits:
-
Object
- Object
- Cuporter::FeatureParser
- Defined in:
- lib/cuporter/feature_parser.rb
Direct Known Subclasses
Constant Summary collapse
- FEATURE_LINE =
/^\s*(Feature:[^#]*)/u
- TAG_LINE =
/^\s*(@\w.+)/u
- SCENARIO_LINE =
/^\s*(Scenario:[^#]*)$/u
- SCENARIO_OUTLINE_LINE =
/^\s*(Scenario Outline:[^#]*)$/u
- SCENARIO_SET_LINE =
/^\s*(Scenarios:[^#]*)$/u
- EXAMPLE_SET_LINE =
/^\s*(Examples:[^#]*)$/u
- EXAMPLE_LINE =
/^\s*(\|.*\|)\s*$/u
- PY_STRING_LINE =
/^\s*"""\s*$/u
Instance Attribute Summary collapse
-
#root ⇒ Object
writeonly
Sets the attribute root.
Class Method Summary collapse
-
.node(file, doc, filter, root_dir) ⇒ Object
returns a feature node populated with scenarios.
-
.tag_nodes(file, report, filter, root_dir) ⇒ Object
adds a node to the doc for each cucumber ‘@’ tag, populated with features and scenarios.
Instance Method Summary collapse
- #clean_cuke_line(sub_expression) ⇒ Object
- #file_relative_path ⇒ Object
-
#initialize(file) ⇒ FeatureParser
constructor
A new instance of FeatureParser.
- #parse_feature ⇒ Object
Constructor Details
#initialize(file) ⇒ FeatureParser
Returns a new instance of FeatureParser.
30 31 32 33 34 |
# File 'lib/cuporter/feature_parser.rb', line 30 def initialize(file) @file = file @current_tags = [] @lines = File.read(@file).split(/\n/) end |
Instance Attribute Details
#root=(value) ⇒ Object (writeonly)
Sets the attribute root
28 29 30 |
# File 'lib/cuporter/feature_parser.rb', line 28 def root=(value) @root = value end |
Class Method Details
.node(file, doc, filter, root_dir) ⇒ Object
returns a feature node populated with scenarios
23 24 25 26 27 |
# File 'lib/cuporter/feature_parser.rb', line 23 def self.node(file, doc, filter, root_dir) parser = NodeParser.new(file, doc, filter) parser.root = root_dir parser.parse_feature end |
.tag_nodes(file, report, filter, root_dir) ⇒ Object
adds a node to the doc for each cucumber ‘@’ tag, populated with features and scenarios
16 17 18 19 20 |
# File 'lib/cuporter/feature_parser.rb', line 16 def self.tag_nodes(file, report, filter, root_dir) parser = TagNodesParser.new(file, report, filter) parser.root = root_dir parser.parse_feature end |
Instance Method Details
#clean_cuke_line(sub_expression) ⇒ Object
84 85 86 |
# File 'lib/cuporter/feature_parser.rb', line 84 def clean_cuke_line(sub_expression) sub_expression.strip.escape_apostrophe end |
#file_relative_path ⇒ Object
36 37 38 |
# File 'lib/cuporter/feature_parser.rb', line 36 def file_relative_path @file_relative_path ||= @file.sub(/^.*#{@root}\//,"#{@root}/") end |
#parse_feature ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cuporter/feature_parser.rb', line 40 def parse_feature @open_comment_block = false @lines.each do |line| next if @open_comment_block && line !~ PY_STRING_LINE case line when PY_STRING_LINE # toggle, to declare the multiline comment 'heredoc' open or closed @open_comment_block = !@open_comment_block when TAG_LINE # may be more than one tag line @current_tags |= clean_cuke_line($1).split(/\s+/) when FEATURE_LINE @feature = new_feature_node(clean_cuke_line($1), file_relative_path) @current_tags = [] when 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(clean_cuke_line($1)) @current_tags = [] when SCENARIO_OUTLINE_LINE # ... another is when we hit a subsequent "Scenario Outline:" close_scenario_outline @scenario_outline = new_scenario_outline_node(clean_cuke_line($1)) @current_tags = [] when EXAMPLE_SET_LINE, SCENARIO_SET_LINE handle_example_set_line if @example_set @example_set = new_example_set_node(clean_cuke_line($1)) @current_tags = [] when @example_set && EXAMPLE_LINE new_example_line(clean_cuke_line($1)) end end # EOF is the final way that we know we are finished with a "Scenario Outline" close_scenario_outline return @feature end |