Sha256: 30bd1ccfaf8a33446156cedbf7d36b2f11b0c4a1339321c843627a954045df8c
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
module CukePages class Features include Enumerable attr_reader :features def initialize(feature_file_paths) @features = [] feature_file_paths.each { |path| @features << FeatureParser.new(path).parse } end def each @features.each { |f| yield f } end end class FeatureParser def initialize(feature_path) @path = feature_path @feature_text = File.open(@path) { |f| f.read } self end def parse feature = CukePages::Feature.new(filename, title) @feature_text.each_line { |line| if line_match = line.match(/^(\s*Scenario\s*:.*$)/) scenario_parts = @feature_text.partition(line_match[1]) scenario = parse_scenario scenario_parts[1..-1] feature.scenarios << scenario end } feature end private def title title_match = @feature_text.match(/^\s*Feature\s*:(.*)$/) title_match[1].strip if title_match end def filename File.basename(@path) end def parse_scenario parts title_match = parts[0].match(/^\s*Scenario\s*:(.*)$/) title = title_match[1].strip if title_match steps = [] parts[1].each_line { |step| if step_match = step.match(/^\s*(Given|When|Then|And)\s*(.*)/) steps << CukePages::Step.new(step_match[1], step_match[2]) elsif step.match(/^\s*Scenario\s*:(.*)$/) break end } CukePages::Scenario.new(title, steps) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cukepages-0.0.4 | lib/cukepages/feature_parser.rb |