1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
# frozen_string_literal: true
require 'parallel_tests'
module ParallelTests
module Gherkin
module Io
def prepare_io(path_or_io)
if path_or_io.respond_to?(:write)
path_or_io
else # its a path
File.open(path_or_io, 'w').close # clean out the file
file = File.open(path_or_io, 'a')
at_exit do
unless file.closed?
file.flush
file.close
end
end
file
end
end
# do not let multiple processes get in each others way
def lock_output
if @io.is_a?(File)
begin
@io.flock File::LOCK_EX
yield
ensure
@io.flock File::LOCK_UN
end
else
yield
end
end
end
end
end
|