blob: 875bdc0852e792166072816ee1feb8952133f578 (
plain)
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
|
# frozen_string_literal: true
require 'yaml'
require 'rspec/core/formatters/base_formatter'
require_relative '../../tooling/lib/tooling/helpers/duration_formatter'
module Support
module RSpecRunTime
class RSpecFormatter < RSpec::Core::Formatters::BaseFormatter
include Tooling::Helpers::DurationFormatter
RSpec::Core::Formatters.register self, :example_group_started, :example_group_finished
def start(_notification)
@group_level = 0
@rspec_test_suite_start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
output.puts "\n# Starting RSpec timer..."
end
def example_group_started(_notification)
@start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) if @group_level == 0
@group_level += 1
end
def example_group_finished(notification)
@group_level -= 1 if @group_level > 0
return unless @group_level == 0
time_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
duration = time_now - @start_time
elapsed_time = time_now - @rspec_test_suite_start_time
output.puts "\n# Example group #{notification.group.description} " \
"(#{notification.group.metadata[:file_path]}) took #{readable_duration(duration)}."
output.puts "# RSpec elapsed time: #{readable_duration(elapsed_time)}.\n\n"
end
end
end
end
RSpec.configure do |config|
config.add_formatter Support::RSpecRunTime::RSpecFormatter if ENV['GITLAB_CI']
end
|