From 47329c05083e19a58920d34c38935815b13ddcca Mon Sep 17 00:00:00 2001 From: Thierry Deo Date: Mon, 5 Sep 2022 09:30:28 +0200 Subject: [PATCH] Fix pollution between tests --- lib/rubocop/rspec/shared_contexts.rb | 10 +++++++++- spec/rubocop/server/rubocop_server_spec.rb | 8 -------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/rubocop/rspec/shared_contexts.rb b/lib/rubocop/rspec/shared_contexts.rb index 906b86b895a..c0fdc1496b0 100644 --- a/lib/rubocop/rspec/shared_contexts.rb +++ b/lib/rubocop/rspec/shared_contexts.rb @@ -2,7 +2,13 @@ require 'tmpdir' -RSpec.shared_context 'isolated environment' do +RSpec.shared_context 'isolated environment' do # rubocop:disable Metrics/BlockLength + before do + # Bust server cache to behave as an isolated environment + RuboCop::Server::Cache.cache_root_path = nil + RuboCop::Server::Cache.instance_variable_set(:@project_dir_cache_key, nil) + end + around do |example| Dir.mktmpdir do |tmpdir| original_home = Dir.home @@ -32,6 +38,8 @@ ENV['HOME'] = original_home ENV['XDG_CONFIG_HOME'] = original_xdg_config_home + RuboCop::Server::Cache.cache_root_path = nil + RuboCop::Server::Cache.instance_variable_set(:@project_dir_cache_key, nil) RuboCop::FileFinder.root_level = nil end end diff --git a/spec/rubocop/server/rubocop_server_spec.rb b/spec/rubocop/server/rubocop_server_spec.rb index ff136e603ce..66e5351c5d6 100644 --- a/spec/rubocop/server/rubocop_server_spec.rb +++ b/spec/rubocop/server/rubocop_server_spec.rb @@ -21,10 +21,6 @@ end it 'displays a restart information message' do - # FIXME: Avoid flaky test for RSpec 4. It may be related that test-queue is not available. - # https://github.com/rubocop/rubocop/pull/10806#discussion_r918415067 - skip if ENV['GITHUB_JOB'] == 'rspec4' - create_file('example.rb', <<~RUBY) # frozen_string_literal: true @@ -40,10 +36,6 @@ context 'when using `--server` option after running server and updating configuration' do it 'applies .rubocop.yml configuration changes even during server startup' do - # FIXME: Avoid flaky test for RSpec 4. It may be related that test-queue is not available. - # https://github.com/rubocop/rubocop/pull/10806#discussion_r918415067 - skip if ENV['GITHUB_JOB'] == 'rspec4' - create_file('example.rb', <<~RUBY) x = 0 puts x