module ParallelTests::Gherkin::Io

Public Instance Methods

lock_output() { || ... } click to toggle source

do not let multiple processes get in each others way

# File lib/parallel_tests/gherkin/io.rb, line 26
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
prepare_io(path_or_io) click to toggle source
# File lib/parallel_tests/gherkin/io.rb, line 7
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