From d9a307266f3a43fc527600652233e8f082343940 Mon Sep 17 00:00:00 2001 From: Andy Waite <13400+andyw8@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:33:13 -0400 Subject: [PATCH] wip --- test/setup_bundler_test.rb | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index 77f3b6059..21030a633 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -226,13 +226,15 @@ def test_does_only_updates_every_4_hours end def test_uses_absolute_bundle_path_for_bundle_install - Bundler.settings.temporary(path: "vendor/bundle") do - Object.any_instance.expects(:system).with( - bundle_env(".ruby-lsp/Gemfile"), - "(bundle check || bundle install) 1>&2", - ).returns(true) - Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}).at_least_once - run_script(expected_path: File.expand_path("vendor/bundle", Dir.pwd)) + with_isolated_bundler do + Bundler.settings.temporary(path: "vendor/bundle") do + Object.any_instance.expects(:system).with( + bundle_env(".ruby-lsp/Gemfile"), + "(bundle check || bundle install) 1>&2", + ).returns(true) + Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}).at_least_once + run_script(expected_path: File.expand_path("vendor/bundle", Dir.pwd)) + end end ensure FileUtils.rm_r(".ruby-lsp") @@ -595,6 +597,21 @@ def test_recovers_from_stale_lockfiles private + def with_isolated_bundler + Bundler.with_unbundled_env do + old_values = Bundler.instance_variables.to_h do |name| + [name, Bundler.instance_variable_get(name)] + end + Bundler.instance_variables.each { |name| Bundler.remove_instance_variable(name) } + yield + ensure + Bundler.instance_variables.each { |name| Bundler.remove_instance_variable(name) } + T.must(old_values).each do |name, value| + Bundler.instance_variable_set(name, value) + end + end + end + # This method runs the script and then immediately unloads it. This allows us to make assertions against the effects # of running the script multiple times def run_script(path = "/fake/project/path", expected_path: nil, **options)