lib/aipim-rails/parser.rb in aipim-rails-0.0.139 vs lib/aipim-rails/parser.rb in aipim-rails-0.0.157
- old
+ new
@@ -4,73 +4,107 @@
def self.init(filename)
parser(filename)
end
- def self.read_line(file)
- line = file.gets
- line = line.gsub("\n", "").split(' ').join(' ') unless line.nil?
- line
+
+ def self.tag_screenshot(line,file,workset)
+ if line && ParserHelper.is_marcacao?(line) && ParserHelper.is_screenshot?(line)
+ workset[:screenshot] = true
+ line = ParserHelper::read_line(file)
+ end
+ return line, file, workset
end
+ def self.tag_feature(line,file,workset)
+ if line && ParserHelper.is_funcionalidade?(line)
+ workset[:feature_name] = ParserHelper.get_funcionalidade(line)
+ while ((line = ParserHelper::read_line(file)) && !ParserHelper.is_comando?(line))
+ workset[:feature_description] << line if !(line.gsub(" ", "") == "")
+ end
+ end
+ return line, file, workset
+ end
+
+ def self.tag_context(line,file,workset)
+ if line && ParserHelper.is_contexto?(line)
+ while ((line = ParserHelper::read_line(file)) && !ParserHelper.is_comando?(line))
+ workset[:context_description] << line if !(line.gsub(" ", "") == "")
+ end
+ end
+ return line, file, workset
+ end
+
+ def self.tag_scenario(line,file,workset)
+ if line && ParserHelper.is_cenario?(line)
+ scenario_name = ParserHelper.get_cenario(line)
+ scenario_steps = []
+ while ((line = ParserHelper::read_line(file)) && !ParserHelper.is_comando?(line))
+ scenario_steps << line if !(line.gsub(" ", "") == "")
+ end
+ if workset[:screenshot]
+ screenshot = workset[:screenshots][workset[:screenshot_counter]].to_s
+ workset[:screenshot_counter] += 1
+ workset[:screenshot] = false
+ end
+ workset[:scenarios] << {name: scenario_name, steps: scenario_steps, screenshot: screenshot}
+ end
+ return line, file, workset
+ end
+
def self.parser(filename)
- file = File.new("features/"+filename, "r")
+ # Read input
+ file = read_file(filename)
- screenshots = %x[\ls aipim/screenshots/#{filename}].split("\n")
+ # Get screenshot files
+ screenshots = get_screenshot_files(filename)
- is_screenshot = false; scenario_counter = 1; screenshot_counter = 0
- feature = []; feature_name = nil; feature_description = []
- context_name = nil; context_description = []
- scenarios = []; scenario_name = nil; scenario_steps = []; screenshot = nil
+ workset = {
+ screenshot: false,
+ screenshot_counter: 0,
+ screenshots: screenshots,
+ feature_name: nil,
+ feature_description: [],
+ context_name: nil,
+ context_description: [],
+ scenarios: []
+ }
- line = read_line(file)
+ line = ParserHelper::read_line(file)
while (line)
- if ParserHelper.is_marcacao?(line) && ParserHelper.is_screenshot?(line)
- is_screenshot = true
- line = read_line(file)
-
- elsif ParserHelper.is_funcionalidade?(line)
- feature_name = ParserHelper.get_funcionalidade(line)
- while ((line = read_line(file)) && !ParserHelper.is_comando?(line))
- feature_description << line if !(line.gsub(" ", "") == "")
- end
+ line, file, workset = tag_screenshot(line, file, workset)
- elsif ParserHelper.is_contexto?(line)
- while ((line = read_line(file)) && !ParserHelper.is_comando?(line))
- context_description << line if !(line.gsub(" ", "") == "")
- end
+ line, file, workset = tag_feature(line, file, workset)
- elsif ParserHelper.is_cenario?(line)
- scenario_name = ParserHelper.get_cenario(line)
- while ((line = read_line(file)) && !ParserHelper.is_comando?(line))
- scenario_steps << line if !(line.gsub(" ", "") == "")
- end
- if is_screenshot
- screenshot = screenshots[screenshot_counter].to_s
- screenshot_counter = screenshot_counter+1
- is_screenshot = false
- end
- scenarios << {name: scenario_name, steps: scenario_steps, screenshot: screenshot}
- scenario_steps = []
- screenshot = nil
+ line, file, workset = tag_context(line, file, workset)
- else
- line = read_line(file)
- end
+ line, file, workset = tag_scenario(line, file, workset)
+
+ line = ParserHelper::read_line(file) unless ParserHelper.is_comando?(line)
end
file.close
feature = {
- feature_name: feature_name,
- feature_description: feature_description,
- context_name: context_name,
- context_description: context_description,
- scenarios: scenarios,
+ feature_name: workset[:feature_name],
+ feature_description: workset[:feature_description],
+ context_name: workset[:context_name],
+ context_description: workset[:context_description],
+ scenarios: workset[:scenarios],
filename: filename
}
+ end
+
+ def self.read_file(filename)
+ filename = "features/"+filename
+ raise "FileNotFound" unless File.exists?(filename)
+ File.open(filename, "r")
+ end
+
+ def self.get_screenshot_files(filename)
+ %x[\ls aipim/screenshots/#{filename}].split("\n")
end
end