File: verbose_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 (62 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

require 'rspec/core/formatters/base_text_formatter'
require 'parallel_tests/rspec/runner'

class ParallelTests::RSpec::VerboseLogger < RSpec::Core::Formatters::BaseTextFormatter
  RSpec::Core::Formatters.register(
    self,
    :example_group_started,
    :example_group_finished,
    :example_started,
    :example_passed,
    :example_pending,
    :example_failed
  )

  def initialize(output)
    super
    @line = []
  end

  def example_group_started(notification)
    @line.push(notification.group.description)
  end

  def example_group_finished(_notification)
    @line.pop
  end

  def example_started(notification)
    @line.push(notification.example.description)
    output_formatted_line('STARTED', :yellow)
  end

  def example_passed(_passed)
    output_formatted_line('PASSED', :success)
    @line.pop
  end

  def example_pending(_pending)
    output_formatted_line('PENDING', :pending)
    @line.pop
  end

  def example_failed(_failure)
    output_formatted_line('FAILED', :failure)
    @line.pop
  end

  private

  def output_formatted_line(status, console_code)
    prefix = ["[#{Process.pid}]"]
    if ENV.include?('TEST_ENV_NUMBER')
      test_env_number = ENV['TEST_ENV_NUMBER'] == '' ? 1 : Integer(ENV['TEST_ENV_NUMBER'])
      prefix << "[#{test_env_number}]"
    end
    prefix << RSpec::Core::Formatters::ConsoleCodes.wrap("[#{status}]", console_code)

    output.puts [*prefix, *@line].join(' ')
  end
end