class Gurk::Parser
Constants
- VALID_STEPS
Attributes
sources[RW]
Public Class Methods
new(sources = Dir.glob("
click to toggle source
# File lib/gurk/parser.rb, line 16 def initialize(sources = Dir.glob("#{Dir.pwd}/features/*.feature")) @parsed_names = [] @parsed_data = [] @sources = sources io = StringIO.new formatter = Gherkin::Formatter::JSONFormatter.new(io) parser = Gherkin::Parser::Parser.new(formatter) read_feature_files(io, parser, formatter, sources) end
Public Instance Methods
parse!()
click to toggle source
# File lib/gurk/parser.rb, line 26 def parse! @parsed_names.each { |name| parse_names(name) } parse_locals(@parsed_data) end
Private Instance Methods
extract_locals_from(step, locals)
click to toggle source
# File lib/gurk/parser.rb, line 73 def extract_locals_from(step, locals) step.reject! { |h| h == locals.first } locals.first end
extract_names_from(steps)
click to toggle source
# File lib/gurk/parser.rb, line 47 def extract_names_from(steps) [].tap { |name| steps.each { |step| name << step['name'] } } end
extract_steps_from(element_nodes)
click to toggle source
# File lib/gurk/parser.rb, line 43 def extract_steps_from(element_nodes) element_nodes.each { |element_node| @parsed_names << extract_names_from(element_node['steps']) } end
merge_steps(step)
click to toggle source
# File lib/gurk/parser.rb, line 78 def merge_steps(step) {}.tap { |data| step.each { |h| data.merge! h } } end
parse_locals(steps)
click to toggle source
# File lib/gurk/parser.rb, line 59 def parse_locals(steps) @parsed_data = [].tap do |data| steps.map do |step| locals = sanitize(step) step << { locals: extract_locals_from(step, locals) } data << merge_steps(step) end end end
parse_names(name)
click to toggle source
# File lib/gurk/parser.rb, line 51 def parse_names(name) @parsed_data << name.map { |match| parse_steps(match) }.flatten.compact end
parse_steps(match)
click to toggle source
# File lib/gurk/parser.rb, line 55 def parse_steps(match) VALID_STEPS.map { |step| step.values.first.call($1, $2) if /#{step.keys.first}/ =~ match } end
process_data(data)
click to toggle source
# File lib/gurk/parser.rb, line 39 def process_data(data) data.each { |feature| extract_steps_from feature['elements'] } end
read_feature_files(io, parser, formatter, sources)
click to toggle source
# File lib/gurk/parser.rb, line 33 def read_feature_files(io, parser, formatter, sources) sources.each { |s| parser.parse(IO.read(s), s, 0) } formatter.done process_data(MultiJson.load(io.string)) end
sanitize(step)
click to toggle source
# File lib/gurk/parser.rb, line 69 def sanitize(step) step.dup.reject! { |h| h.key?(:route) || h.key?(:name) } end