File: runtime_logger.rb

package info (click to toggle)
ruby-parallel-tests 5.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 760 kB
  • sloc: ruby: 5,446; javascript: 16; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 733 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true
require 'parallel_tests/gherkin/io'

module ParallelTests
  module Gherkin
    class RuntimeLogger
      include Io

      def initialize(config)
        @io = prepare_io(config.out_stream)
        @example_times = Hash.new(0)

        config.on_event :test_case_started do |_|
          @start_at = ParallelTests.now.to_f
        end

        config.on_event :test_case_finished do |event|
          @example_times[event.test_case.location.file] += ParallelTests.now.to_f - @start_at
        end

        config.on_event :test_run_finished do |_|
          lock_output do
            @io.puts(@example_times.map { |file, time| "#{file}:#{time}" })
          end
        end
      end
    end
  end
end