Class: Spex::ProcessCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/spex/checks/process_check.rb

Direct Known Subclasses

RestartedCheck, StartedCheck, StoppedCheck

Instance Attribute Summary

Attributes inherited from Check

#options, #target

Instance Method Summary collapse

Methods inherited from Check

[], #active?, #after, as, #before, each, example, examples, #initialize, option, options, #prepare, registry, #to_s, #validate!

Constructor Details

This class inherits a constructor from Spex::Check

Instance Method Details

#current_pidObject



17
18
19
20
21
22
23
24
25
# File 'lib/spex/checks/process_check.rb', line 17

def current_pid
  table = IO.popen(ps_executable) { |ps| ps.readlines }
  table.each do |line|
    if pattern.match(line)
      return line.sub(/^\s+/, '').split(/\s+/)[1]
    end
  end
  nil
end

#patternObject



4
5
6
# File 'lib/spex/checks/process_check.rb', line 4

def pattern
  @pattern ||= target.is_a?(Regexp) ? target : Regexp.new(target)
end

#ps_executableObject



8
9
10
11
12
13
14
15
# File 'lib/spex/checks/process_check.rb', line 8

def ps_executable
  ps = Facter.value(:ps)
  if ps && !ps.empty?
    ps
  else
    abort "Facter does not support 'ps' fact."
  end
end