Sha256: 5fcf3583c9cdadc65469be178cb7cd0d81c6f5ac3411b3447c6507edf68097ad

Contents?: true

Size: 1.23 KB

Versions: 19

Compression:

Stored size: 1.23 KB

Contents

require 'parallel_tests'
require 'parallel_tests/rspec/logger_base'

class ParallelTests::RSpec::RuntimeLogger < ParallelTests::RSpec::LoggerBase
  def initialize(*args)
    super
    @example_times = Hash.new(0)
    @group_nesting = 0
  end

  unless RSPEC_2
    RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished, :start_dump
  end

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

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

  def dump_summary(*args);end
  def dump_failures(*args);end
  def dump_failure(*args);end
  def dump_pending(*args);end

  def start_dump(*args)
    return unless ENV['TEST_ENV_NUMBER'] #only record when running in parallel
    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
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
parallel_tests-3.4.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-3.3.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-3.2.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-3.1.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-3.0.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.32.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.31.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.30.1 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.30.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.29.2 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.29.1 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.29.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.28.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.27.1 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.27.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.26.2 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.26.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.25.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-2.24.0 lib/parallel_tests/rspec/runtime_logger.rb