Class: ParallelTests::Cucumber::Runner

Inherits:
Test::Runner show all
Defined in:
lib/parallel_tests/cucumber/runner.rb

Constant Summary collapse

NAME =
'Cucumber'

Class Method Summary collapse

Methods inherited from Test::Runner

execute_command, execute_command_and_capture_output, find_results, name, test_env_number

Class Method Details

.cucumber_opts(given) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/parallel_tests/cucumber/runner.rb', line 72

def cucumber_opts(given)
  if given =~ /--profile/ or given =~ /(^|\s)-p /
    given
  else
    [given, profile_from_config].compact.join(" ")
  end
end

.determine_executableObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/parallel_tests/cucumber/runner.rb', line 23

def determine_executable
  case
  when File.exists?("bin/cucumber")
    "bin/cucumber"
  when ParallelTests.bundler_enabled?
    "bundle exec cucumber"
  when File.file?("script/cucumber")
    "script/cucumber"
  else
    "cucumber"
  end
end

.line_is_result?(line) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/parallel_tests/cucumber/runner.rb', line 48

def line_is_result?(line)
  line =~ /^\d+ (steps?|scenarios?)/
end

.profile_from_configObject



80
81
82
83
84
85
86
# File 'lib/parallel_tests/cucumber/runner.rb', line 80

def profile_from_config
  # copied from https://github.com/cucumber/cucumber/blob/master/lib/cucumber/cli/profile_loader.rb#L85
  config = Dir.glob('{,.config/,config/}cucumber{.yml,.yaml}').first
  if config && File.read(config) =~ /^parallel:/
    "--profile parallel"
  end
end

.run_tests(test_files, process_number, num_processes, options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/parallel_tests/cucumber/runner.rb', line 10

def run_tests(test_files, process_number, num_processes, options)
  sanitized_test_files = test_files.map { |val| Shellwords.escape(val) }
  options = options.merge(:env => {"AUTOTEST" => "1"}) if $stdout.tty? # display color when we are in a terminal
  runtime_logging = " --format ParallelTests::Cucumber::RuntimeLogger --out #{runtime_log}"
  cmd = [
    executable,
    (runtime_logging if File.directory?(File.dirname(runtime_log))),
    cucumber_opts(options[:test_options]),
    *sanitized_test_files
  ].compact.join(" ")
  execute_command(cmd, process_number, num_processes, options)
end

.runtime_logObject



36
37
38
# File 'lib/parallel_tests/cucumber/runner.rb', line 36

def runtime_log
  'tmp/parallel_runtime_cucumber.log'
end

.summarize_results(results) ⇒ Object

cucumber has 2 result lines per test run, that cannot be added 1 scenario (1 failed) 1 step (1 failed)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/parallel_tests/cucumber/runner.rb', line 55

def summarize_results(results)
  sort_order = %w[scenario step failed undefined skipped pending passed]

  %w[scenario step].map do |group|
    group_results = results.grep /^\d+ #{group}/
    next if group_results.empty?

    sums = sum_up_results(group_results)
    sums = sums.sort_by { |word, _| sort_order.index(word) || 999 }
    sums.map! do |word, number|
      plural = "s" if word == group and number != 1
      "#{number} #{word}#{plural}"
    end
    "#{sums[0]} (#{sums[1..-1].join(", ")})"
  end.compact.join("\n")
end

.test_file_nameObject



40
41
42
# File 'lib/parallel_tests/cucumber/runner.rb', line 40

def test_file_name
  "feature"
end

.test_suffixObject



44
45
46
# File 'lib/parallel_tests/cucumber/runner.rb', line 44

def test_suffix
  ".feature"
end

.tests_in_groups(tests, num_groups, options = {}) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/parallel_tests/cucumber/runner.rb', line 88

def tests_in_groups(tests, num_groups, options={})
  if options[:group_by] == :steps
    Grouper.by_steps(find_tests(tests, options), num_groups, options)
  else
    super
  end
end