lib/cukeforker/worker.rb in cukeforker-0.2.1 vs lib/cukeforker/worker.rb in cukeforker-0.2.2
- old
+ new
@@ -1,13 +1,13 @@
module CukeForker
class Worker
include Observable
class << self
- attr_writer :id
- def id; @id ||= -1; end
- end
+ attr_writer :id
+ def id; @id ||= -1; end
+ end
attr_reader :status, :feature, :pid, :format, :out, :id, :data
def initialize(feature, format, out, extra_args = [])
@feature = feature
@@ -38,14 +38,13 @@
execute_cucumber
}
end
def args
- args = %W[--format #{format} --out #{output}]
+ args = Array(format).flat_map { |f| %W[--format #{f} --out #{output(f)}] }
args += @extra_args
args << feature
-
args
end
def text
"[
@@ -55,11 +54,12 @@
#{out}
#{data}
]"
end
- def output
+ def output(format=nil)
+ format = @format if format.nil?
File.join out, "#{basename}.#{format}"
end
def stdout
File.join out, "#{basename}.stdout"
@@ -69,9 +69,18 @@
File.join out, "#{basename}.stderr"
end
def basename
@basename ||= feature.gsub(/\W/, '_')
+ end
+
+ def kill
+ return unless pid
+
+ Process.kill("TERM", pid)
+ Process.wait(pid)
+ rescue
+ # could not kill worker, ignore
end
private
def execute_cucumber