From 81f08de43a4ab4ca424bbd8a24a2b5b04ff741b2 Mon Sep 17 00:00:00 2001 From: Yevhenii Poberezhnyi Date: Mon, 23 Sep 2024 21:13:39 +0300 Subject: [PATCH] Fix bundler env (#2595) --- lib/ruby_lsp/setup_bundler.rb | 4 +++- test/setup_bundler_test.rb | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 7278008f9..4af480055 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -253,7 +253,9 @@ def bundler_settings_as_env # "vendor/bundle"` settings.all.to_h do |e| key = Bundler::Settings.key_for(e) - [key, settings[e].to_s] + value = Array(settings[e]).join(":").tr(" ", ":") + + [key, value] end end diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index ca7ad9bc5..4f4d742c0 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -568,6 +568,31 @@ def test_respects_overridden_bundle_path_when_there_is_bundle_config end end + def test_uses_correct_bundler_env_when_there_is_bundle_config + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + File.write(File.join(dir, "Gemfile"), <<~GEMFILE) + source "https://rubygems.org" + gem "irb" + GEMFILE + + Bundler.with_unbundled_env do + system("bundle config set --local with production staging") + + assert_path_exists(File.join(dir, ".bundle", "config")) + + capture_subprocess_io do + system("bundle install") + + env = run_script(dir) + + assert_equal("production:staging", env["BUNDLE_WITH"]) + end + end + end + end + end + private def with_default_external_encoding(encoding, &block) @@ -597,12 +622,15 @@ def ignore_warnings(&block) # 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 = Dir.pwd, expected_path: nil, **options) + env = T.let({}, T::Hash[String, String]) + stdout, _stderr = capture_subprocess_io do env = RubyLsp::SetupBundler.new(path, **options).setup! assert_equal(expected_path, env["BUNDLE_PATH"]) if expected_path end assert_empty(stdout) + env end # This method needs to be called inside the `Bundler.with_unbundled_env` block IF the command you want to test is @@ -626,7 +654,9 @@ def bundle_env(base_path = Dir.pwd, bundle_gemfile = "Gemfile") env = settings.all.to_h do |e| key = Bundler::Settings.key_for(e) - [key, settings[e].to_s] + value = Array(settings[e]).join(":").tr(" ", ":") + + [key, value] end if env["BUNDLE_PATH"]