Loading lib/labkit/covered_experience.rb +4 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ module Labkit @configuration ||= Configuration.new end def reset_configuration @configuration = nil end def configure yield(configuration) if block_given? end Loading spec/spec_helper.rb +38 −2 Original line number Diff line number Diff line Loading @@ -5,8 +5,6 @@ require "rspec-parameterized" require "pry-byebug" require_relative "helpers/stub_env" require_relative "support/covered_experience_test_config" require_relative "support/metrics_test_config" # Warning#[]= is supported since Ruby 2.7 Warning[:deprecated] = true if Warning.respond_to?(:[]=) Loading @@ -21,4 +19,42 @@ RSpec.configure do |config| end Kernel.srand config.seed # Labkit::Metrics hooks config.around(with_metrics_config: true) do |example| Dir.mktmpdir do |dir| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = dir end Labkit::Metrics::Client.reset! example.run # enabled is the default state of the client # however, if this test is running in a process that has # already initialized the client, it may be previously # disabled, so we explicitly re-enable it before each test Labkit::Metrics::Client.enable! end end config.around(without_metrics_config: true) do |example| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = nil end example.run end # Labkit::CoveredExperience hooks config.around do |example| Labkit::CoveredExperience.configure do |config| # Ignore logs by default in tests config.logger = Labkit::Logging::JsonLogger.new("/dev/null") end example.run Labkit::CoveredExperience.reset_configuration end end spec/support/covered_experience_test_config.rbdeleted 100644 → 0 +0 −14 Original line number Diff line number Diff line # frozen_string_literal: true # Test configuration for Labkit::CoveredExperience to ignore logs by default in tests RSpec.configure do |config| config.before do Labkit::CoveredExperience.configure do |config| config.logger = Labkit::Logging::JsonLogger.new("/dev/null") end end config.after do Labkit::CoveredExperience.instance_variable_set(:@configuration, nil) end end spec/support/metrics_test_config.rbdeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line # frozen_string_literal: true # Test configuration for Labkit::Metrics::Client RSpec.configure do |config| config.around(with_metrics_config: true) do |example| Dir.mktmpdir do |dir| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = dir end Labkit::Metrics::Client.reset! example.run # enabled is the default state of the client # however, if this test is running in a process that has # already initialized the client, it may be previously # disabled, so we explicitly re-enable it before each test Labkit::Metrics::Client.enable! end end config.around(without_metrics_config: true) do |example| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = nil end example.run end end Loading
lib/labkit/covered_experience.rb +4 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,10 @@ module Labkit @configuration ||= Configuration.new end def reset_configuration @configuration = nil end def configure yield(configuration) if block_given? end Loading
spec/spec_helper.rb +38 −2 Original line number Diff line number Diff line Loading @@ -5,8 +5,6 @@ require "rspec-parameterized" require "pry-byebug" require_relative "helpers/stub_env" require_relative "support/covered_experience_test_config" require_relative "support/metrics_test_config" # Warning#[]= is supported since Ruby 2.7 Warning[:deprecated] = true if Warning.respond_to?(:[]=) Loading @@ -21,4 +19,42 @@ RSpec.configure do |config| end Kernel.srand config.seed # Labkit::Metrics hooks config.around(with_metrics_config: true) do |example| Dir.mktmpdir do |dir| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = dir end Labkit::Metrics::Client.reset! example.run # enabled is the default state of the client # however, if this test is running in a process that has # already initialized the client, it may be previously # disabled, so we explicitly re-enable it before each test Labkit::Metrics::Client.enable! end end config.around(without_metrics_config: true) do |example| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = nil end example.run end # Labkit::CoveredExperience hooks config.around do |example| Labkit::CoveredExperience.configure do |config| # Ignore logs by default in tests config.logger = Labkit::Logging::JsonLogger.new("/dev/null") end example.run Labkit::CoveredExperience.reset_configuration end end
spec/support/covered_experience_test_config.rbdeleted 100644 → 0 +0 −14 Original line number Diff line number Diff line # frozen_string_literal: true # Test configuration for Labkit::CoveredExperience to ignore logs by default in tests RSpec.configure do |config| config.before do Labkit::CoveredExperience.configure do |config| config.logger = Labkit::Logging::JsonLogger.new("/dev/null") end end config.after do Labkit::CoveredExperience.instance_variable_set(:@configuration, nil) end end
spec/support/metrics_test_config.rbdeleted 100644 → 0 +0 −29 Original line number Diff line number Diff line # frozen_string_literal: true # Test configuration for Labkit::Metrics::Client RSpec.configure do |config| config.around(with_metrics_config: true) do |example| Dir.mktmpdir do |dir| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = dir end Labkit::Metrics::Client.reset! example.run # enabled is the default state of the client # however, if this test is running in a process that has # already initialized the client, it may be previously # disabled, so we explicitly re-enable it before each test Labkit::Metrics::Client.enable! end end config.around(without_metrics_config: true) do |example| Labkit::Metrics::Client.configure do |metrics_config| metrics_config.multiprocess_files_dir = nil end example.run end end