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



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

def dump_failure(*)
end

#dump_failuresObject



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

def dump_failures(*)
end

#dump_pendingObject



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

def dump_pending(*)
end

#dump_summaryObject



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

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
30
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 29

def seed(*)
end

#start_dumpObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/parallel_specs/rspec/runtime_logger.rb', line 44

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