Class: ParallelTests::RSpec::RuntimeLogger

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

Constant Summary

Constants inherited from LoggerBase

LoggerBase::RSPEC_1, LoggerBase::RSPEC_2, LoggerBase::RSPEC_3

Instance Method Summary collapse

Methods inherited from LoggerBase

#close

Constructor Details

#initialize(*args) ⇒ RuntimeLogger

Returns a new instance of RuntimeLogger.



5
6
7
8
9
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 5

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

Instance Method Details

#dump_failure(*args) ⇒ Object



45
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 45

def dump_failure(*args);end

#dump_failures(*args) ⇒ Object



44
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 44

def dump_failures(*args);end

#dump_pending(*args) ⇒ Object



46
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 46

def dump_pending(*args);end

#dump_summary(*args) ⇒ Object



43
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 43

def dump_summary(*args);end

#example_group_finished(notification) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 33

def example_group_finished(notification)
  @group_nesting -= 1
  if @group_nesting == 0
    path = (RSPEC_3 ? notification.group.file_path : notification.file_path)
    @example_times[path] += ParallelTests.now - @time
  end
  super if defined?(super)
end

#example_group_started(example_group) ⇒ Object



27
28
29
30
31
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 27

def example_group_started(example_group)
  @time = ParallelTests.now if @group_nesting == 0
  @group_nesting += 1
  super
end

#example_passed(example) ⇒ Object



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

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

#example_started(*args) ⇒ Object



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

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

#start_dump(*args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/parallel_tests/rspec/runtime_logger.rb', line 48

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
    @example_times.each do |file, time|
      relative_path = file.sub(/^#{Regexp.escape Dir.pwd}\//,'').sub(/^\.\//, "")
      @output.puts "#{relative_path}:#{time > 0 ? time : 0}"
    end
  end
  @output.flush
end