Class: CukeForker::Worker

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/cukeforker/worker.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature, format, out, extra_args = []) ⇒ Worker

Returns a new instance of Worker.



12
13
14
15
16
17
18
19
20
21
# File 'lib/cukeforker/worker.rb', line 12

def initialize(feature, format, out, extra_args = [])
  @feature      = feature
  @format       = format
  @extra_args   = extra_args
  @out          = out
  @status       = nil
  @data         = OpenStruct.new

  @id = self.class.id += 1
end

Class Attribute Details

.idObject



7
# File 'lib/cukeforker/worker.rb', line 7

def id; @id ||= -1; end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def data
  @data
end

#featureObject (readonly)

Returns the value of attribute feature.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def feature
  @feature
end

#formatObject (readonly)

Returns the value of attribute format.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def format
  @format
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def id
  @id
end

#outObject (readonly)

Returns the value of attribute out.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def out
  @out
end

#pidObject (readonly)

Returns the value of attribute pid.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def pid
  @pid
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/cukeforker/worker.rb', line 10

def status
  @status
end

Instance Method Details

#argsObject



42
43
44
45
46
47
48
# File 'lib/cukeforker/worker.rb', line 42

def args
  args = %W[--format #{format} --out #{output}]
  args += @extra_args
  args << feature

  args
end

#basenameObject



72
73
74
# File 'lib/cukeforker/worker.rb', line 72

def basename
  @basename ||= feature.gsub(/\W/, '_')
end

#failed?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cukeforker/worker.rb', line 30

def failed?
  status.nil? || status.exitstatus != 0
end

#finished?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/cukeforker/worker.rb', line 23

def finished?
  wait_pid, @status = Process.waitpid2(pid, Process::WNOHANG)
  !!wait_pid
rescue Errno::ECHILD, Errno::ESRCH
  true
end

#outputObject



60
61
62
# File 'lib/cukeforker/worker.rb', line 60

def output
  File.join out, "#{basename}.#{format}"
end

#startObject



34
35
36
37
38
39
40
# File 'lib/cukeforker/worker.rb', line 34

def start
  @pid = Process.fork {
    changed
    notify_observers :on_worker_forked, self
    execute_cucumber
  }
end

#stderrObject



68
69
70
# File 'lib/cukeforker/worker.rb', line 68

def stderr
  File.join out, "#{basename}.stderr"
end

#stdoutObject



64
65
66
# File 'lib/cukeforker/worker.rb', line 64

def stdout
  File.join out, "#{basename}.stdout"
end

#textObject



50
51
52
53
54
55
56
57
58
# File 'lib/cukeforker/worker.rb', line 50

def text
  "[
    #{pid}
    #{feature}
    #{status.inspect}
    #{out}
    #{data}
   ]"
end