Sha256: 1dc31694942e6aa3c9e41f8f0c33a5032c288f41028926cd9b692d7843e38737

Contents?: true

Size: 771 Bytes

Versions: 6

Compression:

Stored size: 771 Bytes

Contents

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

6 entries across 6 versions & 1 rubygems

Version Path
parallel_tests-0.12.0 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.11.6 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.11.5 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.11.4 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.11.3 lib/parallel_tests/cucumber/io.rb
parallel_tests-0.11.2 lib/parallel_tests/cucumber/io.rb