Sha256: 45878a8d81db0a9dd910b904c75147fb398abd2787e1c6d364e4c04362410a76

Contents?: true

Size: 1.37 KB

Versions: 28

Compression:

Stored size: 1.37 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 if !RSPEC_1
  end

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

    def example_passed(example)
      file = example.location.split(':').first
      @example_times[file] += ParallelTests.now - @time
      super
    end
  else
    def example_group_started(example_group)
      @time = ParallelTests.now if @group_nesting == 0
      @group_nesting += 1
      super
    end

    def example_group_finished(example_group)
      @group_nesting -= 1
      if @group_nesting == 0
        @example_times[example_group.file_path] += ParallelTests.now - @time
      end
      super
    end
  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
    # 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}\//,'')
        @output.puts "#{relative_path}:#{time > 0 ? time : 0}"
      end
    end
    @output.flush
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
parallel_tests-0.16.17 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.16 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.15 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.14 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.13 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.12 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.11 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.10 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.9 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.8 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.7 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.6 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.5 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.4 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.3 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.2 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.1 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.16.0 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.15.4 lib/parallel_tests/rspec/runtime_logger.rb
parallel_tests-0.15.3 lib/parallel_tests/rspec/runtime_logger.rb