Sha256: 154cdfb186ae7428d9d81ebfbbbecbfbe2f2c039c715a8f09b5d25c0236e92ef

Contents?: true

Size: 1.01 KB

Versions: 22

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
module ParallelTests
  module RSpec
  end
end

require 'rspec/core/formatters/base_text_formatter'

class ParallelTests::RSpec::LoggerBase < RSpec::Core::Formatters::BaseTextFormatter
  RSPEC_2 = RSpec::Core::Version::STRING.start_with?('2')

  def initialize(*args)
    super

    @output ||= args[0]

    case @output
    when String # a path ?
      FileUtils.mkdir_p(File.dirname(@output))
      File.open(@output, 'w') {} # overwrite previous results
      @output = File.open(@output, 'a')
    when File # close and restart in append mode
      @output.close
      @output = File.open(@output.path, 'a')
    end
  end

  # stolen from Rspec
  def close(*)
    @output.close if (IO === @output) & (@output != $stdout)
  end

  protected

  # do not let multiple processes get in each others way
  def lock_output
    if @output.is_a?(File)
      begin
        @output.flock File::LOCK_EX
        yield
      ensure
        @output.flock File::LOCK_UN
      end
    else
      yield
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
parallel_tests-4.2.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-4.2.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-4.1.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-4.0.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.13.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.12.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.12.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.11.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.11.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.10.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.10.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.9.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.9.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.8.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.8.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.7.3 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.7.1 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.7.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.6.0 lib/parallel_tests/rspec/logger_base.rb
parallel_tests-3.5.2 lib/parallel_tests/rspec/logger_base.rb