Class: Cuporter::FeatureParser
- Inherits:
-
Object
- Object
- Cuporter::FeatureParser
- Defined in:
- lib/cuporter/feature_parser.rb
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
- #close_scenario_outline ⇒ Object
-
#initialize(file) ⇒ FeatureParser
constructor
A new instance of FeatureParser.
- #parse ⇒ Object
Constructor Details
#initialize(file) ⇒ FeatureParser
Returns a new instance of FeatureParser.
13 14 15 16 |
# File 'lib/cuporter/feature_parser.rb', line 13 def initialize(file) @file = file @current_tags = [] end |
Class Method Details
.parse(file) ⇒ Object
18 19 20 |
# File 'lib/cuporter/feature_parser.rb', line 18 def self.parse(file) self.new(file).parse end |
Instance Method Details
#close_scenario_outline ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cuporter/feature_parser.rb', line 62 def close_scenario_outline if @scenario_outline if @example_set @scenario_outline.add_to_tag_nodes(@example_set) if @example_set @example_set = nil end @feature.merge(@scenario_outline) @scenario_outline = nil end end |
#parse ⇒ Object
22 23 24 25 26 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 |
# File 'lib/cuporter/feature_parser.rb', line 22 def parse lines = File.read(@file).split(/\n/) lines.each_with_index do |line, i| case line when TAG_LINE # may be more than one tag line @current_tags |= $1.strip.split(/\s+/) when FEATURE_LINE @feature = TagListNode.new($1, @current_tags) @feature.file = @file.sub(/^.*features\//,"features/") @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 @feature.add_to_tag_nodes(TagListNode.new($1, @current_tags)) @current_tags = [] when SCENARIO_OUTLINE_LINE # ... another is when we hit a subsequent "Scenario Outline:" close_scenario_outline @scenario_outline = TagListNode.new($1, @current_tags) @current_tags = [] when EXAMPLE_SET_LINE, SCENARIO_SET_LINE @scenario_outline.add_to_tag_nodes(@example_set) if @example_set @example_set = ExampleSetNode.new($1, @feature. | @current_tags) @current_tags = [] when @example_set && 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 |