Class: ParallelSpecs::RSpec::RuntimeLogger

Inherits:
LoggerBase
  • Object
show all
Defined in:
lib/parallel_specs/rspec/runtime_logger.rb

Instance Method Summary collapse

Methods inherited from LoggerBase

#close

Constructor Details

#initialize(*args) ⇒ RuntimeLogger

Returns a new instance of RuntimeLogger.



9
10
11
12
13
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 9

def initialize(*args)
  super
  @example_times = Hash.new(0)
  @group_nesting = 0
end

Instance Method Details

#dump_failureObject



32
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 32

def dump_failure(*); end

#dump_failuresObject



31
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 31

def dump_failures(*); end

#dump_pendingObject



33
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 33

def dump_pending(*); end

#dump_summaryObject



30
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 30

def dump_summary(*); end

#example_group_finished(notification) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 21

def example_group_finished(notification)
  @group_nesting -= 1
  if @group_nesting.zero?
    @example_times[notification.group.file_path] += ParallelSpecs.now - @time
  end
  super if defined?(super)
end

#example_group_started(example_group) ⇒ Object



15
16
17
18
19
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 15

def example_group_started(example_group)
  @time = ParallelSpecs.now if @group_nesting.zero?
  @group_nesting += 1
  super
end

#seedObject



29
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 29

def seed(*); end

#start_dumpObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 35

def start_dump(*)
  return unless ENV['TEST_ENV_NUMBER']

  lock_output do
    @example_times.sort_by(&:last).reverse_each do |file, time|
      relative_path = file.sub(%r{^#{Regexp.escape(Dir.pwd)}/}, '').sub(%r{^\./}, '')
      @output.puts "#{relative_path}:#{[time, 0].max}"
    end
  end
  @output.flush
end