class CucumberJunitToJson::Parsers::FeatureParser

Abstract representation of a cucumber feature file parser

Constants

Error

Attributes

path_to_features[RW]

Public Class Methods

new(path_to_features) click to toggle source
# File lib/cucumber_junit_to_json/parsers/feature_parser.rb, line 14
def initialize(path_to_features)
  STDERR.puts 'warning: no junit directory given' if path_to_features.empty?
  raise Error, "no such dir(s): #{path_to_features}" unless Dir.exist?(path_to_features)
  @path_to_features = path_to_features
end

Public Instance Methods

tags_and_line_number_matching(file, text, similar = false) click to toggle source
# File lib/cucumber_junit_to_json/parsers/feature_parser.rb, line 20
def tags_and_line_number_matching(file, text, similar = false)
  tags, line = text_and_line_number_before_match(file, text, similar)
  tag_objects = []
  tags.split(' ').each do |tag|
    if tag.strip.start_with?('@')
      tag_objects.push(CucumberJunitToJson::Models::Tag.new(tag, line - 1))
    end
  end
  [tag_objects, line]
end
text_and_line_number_before_match(file, text, similar = false) click to toggle source
# File lib/cucumber_junit_to_json/parsers/feature_parser.rb, line 31
def text_and_line_number_before_match(file, text, similar = false)
  count = 0
  prev_line_text = ''
  File.open(file, 'r') do |f|
    f.each_line do |line|
      count += 1
      if similar && line =~ /<\S+>/
        return prev_line_text, count if line.similar(text) >= 73
      elsif line =~ /#{text}/
        return prev_line_text, count
      end
      prev_line_text = line
    end
  end
  raise Error, "Could not find #{text} in #{file}"
end
text_and_line_number_matching(file, text, similar = false) click to toggle source
# File lib/cucumber_junit_to_json/parsers/feature_parser.rb, line 48
def text_and_line_number_matching(file, text, similar = false)
  count = 0
  File.open(file, 'r') do |f|
    f.each_line do |line|
      count += 1
      if similar || line =~ /<\S+>/
        return line, count if line.similar(text) >= 73
      elsif line =~ /#{text}/
        return line, count
      end
    end
  end
  raise Error, "Could not find #{text} in #{file}"
end