Class: ParallelTests::RSpec::LoggerBase

Inherits:
LoggerBaseBase
  • Object
show all
Defined in:
lib/parallel_tests/rspec/logger_base.rb

Direct Known Subclasses

FailuresLogger, RuntimeLogger, SummaryLogger

Constant Summary collapse

RSPEC_1 =

do not test for Spec, this will trigger deprecation warning in rspec 2

!defined?(RSpec::Core::Formatters::BaseTextFormatter) # do not test for Spec, this will trigger deprecation warning in rspec 2

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ LoggerBase

Returns a new instance of LoggerBase.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parallel_tests/rspec/logger_base.rb', line 19

def initialize(*args)
  super

  @output ||= args[1] || args[0] # rspec 1 has output as second argument

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

Instance Method Details

#closeObject

stolen from Rspec



35
36
37
# File 'lib/parallel_tests/rspec/logger_base.rb', line 35

def close
  @output.close  if (IO === @output) & (@output != $stdout)
end

#lock_outputObject

do not let multiple processes get in each others way



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/parallel_tests/rspec/logger_base.rb', line 40

def lock_output
  if File === @output
    begin
      @output.flock File::LOCK_EX
      yield
    ensure
      @output.flock File::LOCK_UN
    end
  else
    yield
  end
end