Sha256: 58d1dbcdb2c83c32498b6e45ed11670f92e6ed2120c3bd3a3a88ba9bcd9876e3

Contents?: true

Size: 797 Bytes

Versions: 9

Compression:

Stored size: 797 Bytes

Contents

require 'parallel_tests'

module ParallelTests
  module Cucumber
    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 File === @io
          begin
            @io.flock File::LOCK_EX
            yield
          ensure
            @io.flock File::LOCK_UN
          end
        else
          yield
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
vinted-parallel_tests-0.13.3 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.13.3 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.13.2 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.13.1 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.13.0 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.12.4 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.12.3 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.12.2 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.12.1 lib/parallel_tests/cucumber/io.rb