Commit 00e81a1f authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'alberts-knapsack-track-context' into 'master'

Include context in spec time tracking

See merge request gitlab-org/gitlab!58980
parents 86cf22aa df80738e
# frozen_string_literal: true
require 'knapsack'
module KnapsackEnv
class RSpecContextAdapter < Knapsack::Adapters::RSpecAdapter
def bind_time_tracker
::RSpec.configure do |config|
# Original version starts timer in `config.prepend_before(:each) do`
# https://github.com/KnapsackPro/knapsack/blob/v1.17.0/lib/knapsack/adapters/rspec_adapter.rb#L9
config.prepend_before(:context) do
Knapsack.tracker.start_timer
end
# Original version is `config.prepend_before(:each) do`
# https://github.com/KnapsackPro/knapsack/blob/v1.17.0/lib/knapsack/adapters/rspec_adapter.rb#L9
config.prepend_before(:each) do # rubocop:disable RSpec/HookArgument
current_example_group =
if ::RSpec.respond_to?(:current_example)
::RSpec.current_example.metadata[:example_group]
else
example.metadata
end
Knapsack.tracker.test_path = Knapsack::Adapters::RSpecAdapter.test_path(current_example_group)
end
# Original version stops timer in `config.append_after(:each) do`
# https://github.com/KnapsackPro/knapsack/blob/v1.17.0/lib/knapsack/adapters/rspec_adapter.rb#L20
config.append_after(:context) do
Knapsack.tracker.stop_timer
end
config.after(:suite) do
Knapsack.logger.info(Knapsack::Presenter.global_time)
end
end
end
end
def self.configure!
return unless ENV['CI'] && ENV['KNAPSACK_GENERATE_REPORT'] && !ENV['NO_KNAPSACK']
RSpecContextAdapter.bind
end
end
...@@ -15,6 +15,9 @@ Warning[:deprecated] = true unless ENV.key?('SILENCE_DEPRECATIONS') ...@@ -15,6 +15,9 @@ Warning[:deprecated] = true unless ENV.key?('SILENCE_DEPRECATIONS')
require './spec/deprecation_toolkit_env' require './spec/deprecation_toolkit_env'
DeprecationToolkitEnv.configure! DeprecationToolkitEnv.configure!
require './spec/knapsack_env'
KnapsackEnv.configure!
require './spec/simplecov_env' require './spec/simplecov_env'
SimpleCovEnv.start! SimpleCovEnv.start!
...@@ -47,11 +50,6 @@ if rspec_profiling_is_configured && (!ENV.key?('CI') || branch_can_be_profiled) ...@@ -47,11 +50,6 @@ if rspec_profiling_is_configured && (!ENV.key?('CI') || branch_can_be_profiled)
require 'rspec_profiling/rspec' require 'rspec_profiling/rspec'
end end
if ENV['CI'] && ENV['KNAPSACK_GENERATE_REPORT'] && !ENV['NO_KNAPSACK']
require 'knapsack'
Knapsack::Adapters::RSpecAdapter.bind
end
# require rainbow gem String monkeypatch, so we can test SystemChecks # require rainbow gem String monkeypatch, so we can test SystemChecks
require 'rainbow/ext/string' require 'rainbow/ext/string'
Rainbow.enabled = false Rainbow.enabled = false
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment