Module: ParallelSpecs

Defined in:
lib/parallel_specs.rb,
lib/parallel_specs/cli.rb,
lib/parallel_specs/pids.rb,
lib/parallel_specs/grouper.rb,
lib/parallel_specs/version.rb,
lib/parallel_specs/test/runner.rb,
lib/parallel_specs/rspec/runner.rb,
lib/parallel_specs/cli/dashboard.rb,
lib/parallel_specs/rspec/logger_base.rb,
lib/parallel_specs/rspec/dashboard_logger.rb

Defined Under Namespace

Modules: RSpec, Test Classes: CLI, Grouper, Pids

Constant Summary collapse

WINDOWS =
(RbConfig::CONFIG['host_os'] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
RUBY_BINARY =
File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
VERSION =
'0.9.0'

Class Method Summary collapse

Class Method Details

.bundler_enabled?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/parallel_specs.rb', line 65

def bundler_enabled?
  return true if Object.const_defined?(:Bundler)

  previous = nil
  current = File.expand_path(Dir.pwd)
  until !File.directory?(current) || current == previous
    return true if File.exist?(File.join(current, 'Gemfile'))

    previous = current
    current = File.expand_path('..', current)
  end

  false
end

.deltaObject



88
89
90
91
92
# File 'lib/parallel_specs.rb', line 88

def delta
  before = now.to_f
  yield
  now.to_f - before
end

.determine_number_of_processes(count) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/parallel_specs.rb', line 17

def determine_number_of_processes(count)
  Integer([
    count,
    ENV['PARALLEL_SPECS_PROCESSORS'],
    Parallel.processor_count
  ].detect { |value| !value.to_s.strip.empty? })
end

.nowObject



84
85
86
# File 'lib/parallel_specs.rb', line 84

def now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.pid_file_available?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/parallel_specs.rb', line 41

def pid_file_available?
  !ENV['PARALLEL_SPECS_PID_FILE'].to_s.empty?
end

.pid_file_pathObject



45
46
47
# File 'lib/parallel_specs.rb', line 45

def pid_file_path
  ENV.fetch('PARALLEL_SPECS_PID_FILE')
end

.pidsObject



37
38
39
# File 'lib/parallel_specs.rb', line 37

def pids
  @pids ||= Pids.new(pid_file_path)
end

.stop_all_processesObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/parallel_specs.rb', line 49

def stop_all_processes
  return false unless pid_file_available?

  tracked_pids = pids.all
  return false if tracked_pids.empty?

  signal_delivered = false
  tracked_pids.each do |pid|
    Process.kill(:INT, pid)
    signal_delivered = true
  rescue Errno::ESRCH, Errno::EPERM => e
    warn "parallel_specs: unable to interrupt worker pid #{pid}: #{e.class}: #{e.message}"
  end
  signal_delivered
end

.with_pid_fileObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/parallel_specs.rb', line 25

def with_pid_file
  previous_pid_file = ENV['PARALLEL_SPECS_PID_FILE']
  Tempfile.open('parallel_specs-pidfile') do |file|
    ENV['PARALLEL_SPECS_PID_FILE'] = file.path
    @pids = pids
    yield
  ensure
    ENV['PARALLEL_SPECS_PID_FILE'] = previous_pid_file
    @pids = nil
  end
end

.with_ruby_binary(command) ⇒ Object



80
81
82
# File 'lib/parallel_specs.rb', line 80

def with_ruby_binary(command)
  WINDOWS ? [RUBY_BINARY, '--', command] : [command]
end