Class: ParallelSpecs::SpecRuntimeLogger

Inherits:
SpecLoggerBase show all
Defined in:
lib/parallel_specs/spec_runtime_logger.rb

Instance Method Summary collapse

Methods inherited from SpecLoggerBase

#close, #dump_failure, #dump_pending, #dump_summary, #example_failed, #example_pending, #lock_output

Constructor Details

#initialize(options, output = nil) ⇒ SpecRuntimeLogger

Returns a new instance of SpecRuntimeLogger.



5
6
7
8
# File 'lib/parallel_specs/spec_runtime_logger.rb', line 5

def initialize(options, output=nil)
  super
  @example_times = Hash.new(0)
end

Instance Method Details

#example_passed(example) ⇒ Object



14
15
16
17
# File 'lib/parallel_specs/spec_runtime_logger.rb', line 14

def example_passed(example)
  file = example.location.split(':').first
  @example_times[file] += Time.now - @time
end

#example_started(*args) ⇒ Object



10
11
12
# File 'lib/parallel_specs/spec_runtime_logger.rb', line 10

def example_started(*args)
  @time = Time.now
end

#start_dump(*args) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/parallel_specs/spec_runtime_logger.rb', line 19

def start_dump(*args)
  return unless ENV['TEST_ENV_NUMBER'] #only record when running in parallel
  # TODO: Figure out why sometimes time can be less than 0
  lock_output do
    @output.puts @example_times.map { |file, time| "#{file}:#{time > 0 ? time : 0}" }
  end
  @output.flush
end