module ParallelCucumber::Helper::Cucumber

Public Class Methods

batch_mapped_files(options, batch, env) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 18
def batch_mapped_files(options, batch, env)
  options = options.dup
  options = expand_profiles(options, env) unless config_file.nil?
  file_map = {}
  options.gsub!(/(?:\s|^)--dry-run\s+/, '')
  options.gsub!(%r{((?:\s|^)(?:--out|-o))\s+((?:\S+\/)?(\S+))}) { "#{$1} #{file_map[$2] = "#{batch}/#{$3}"}" } # rubocop:disable Style/PerlBackrefs, Metrics/LineLength
  [options, file_map]
end
parse_json_report(json_report) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 27
def parse_json_report(json_report)
  report = JSON.parse(json_report, symbolize_names: true)
  report.each do |scenario, details|
    report[scenario][:status] = case details[:status]
                                when 'failed'
                                  Status::FAILED
                                when 'passed'
                                  Status::PASSED
                                when 'pending'
                                  Status::PENDING
                                when 'skipped'
                                  Status::SKIPPED
                                when 'undefined'
                                  Status::UNDEFINED
                                when 'unknown'
                                  Status::UNKNOWN
                                else
                                  Status::UNKNOWN
                                end
  end
  report
end
selected_tests(options, args_string) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 12
def selected_tests(options, args_string)
  puts "selected_tests (#{options.inspect} #{args_string.inspect})"
  dry_run_report = dry_run_report(options, args_string)
  parse_json_report(dry_run_report).keys
end
unknown_result(tests) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 50
def unknown_result(tests)
  res = tests.map do |test|
    [test.to_sym, {status: ::ParallelCucumber::Status::UNKNOWN}]
  end
  res.to_h
end

Private Class Methods

_expand_profiles(options, config) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 107
def _expand_profiles(options, config)
  profiles = options.scan(/(?:^|\s)((?:--profile|-p)\s+[\S]+)/)
  profiles.map(&:first).each do |profile|
    option = profile.gsub(/(--profile|-p)\s+/, '')
    options.gsub!(profile, _expand_profiles(config.fetch(option), config))
  end
  options.strip
end
config_file() click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 103
def config_file
  Dir.glob('{,.config/,config/}cucumber{.yml,.yaml}').first
end
dry_run_report(options, args_string) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 59
def dry_run_report(options, args_string)
  options = options.dup
  options = expand_profiles(options) unless config_file.nil?
  options = remove_formatters(options)
  options = remove_dry_run_flag(options)
  options = remove_strict_flag(options)
  content = nil

  Tempfile.open(%w[dry-run .json]) do |f|
    dry_run_options = "--dry-run --format ParallelCucumber::Helper::Cucumber::JsonStatusFormatter --out #{f.path}"

    cmd = "cucumber #{options} #{dry_run_options} #{args_string}"
    _stdout, stderr, status = Open3.capture3(cmd)
    f.close

    unless status == 0
      cmd = "bundle exec #{cmd}" if ENV['BUNDLE_BIN_PATH']
      raise("Can't generate dry run report: #{status}:\n\t#{cmd}\n\t#{stderr}")
    end

    content = File.read(f.path)
  end
  content
end
expand_profiles(options, env = {}) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 84
def expand_profiles(options, env = {})
  mutex.synchronize do
    e = ENV.to_h
    ENV.replace(e.merge(env))
    begin
      content = ERB.new(File.read(config_file)).result
      config  = YAML.safe_load(content)
      return _expand_profiles(options, config)
    ensure
      ENV.replace(e)
    end
  end
end
mutex() click to toggle source

@return Mutex

# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 99
def mutex
  @mutex ||= Mutex.new
end
remove_dry_run_flag(options) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 120
def remove_dry_run_flag(options)
  options.gsub(/(^|\s)--dry-run(\s|$)/, ' ')
end
remove_formatters(options) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 116
def remove_formatters(options)
  options.gsub(/(^|\s)(--format|-f|--out|-o)\s+[\S]+/, ' ')
end
remove_strict_flag(options) click to toggle source
# File lib/parallel_cucumber/helper/cucumber/cucumber.rb, line 124
def remove_strict_flag(options)
  options.gsub(/(^|\s)(--strict|-S)(\s|$)/, ' ')
end