From 82e40775fa2125a3da7b6d224f822553acad91b5 Mon Sep 17 00:00:00 2001 From: Yevhenii Poberezhnyi Date: Mon, 23 Sep 2024 20:14:18 +0300 Subject: [PATCH] Fix bundler env --- lib/ruby_lsp/setup_bundler.rb | 4 +++- test/setup_bundler_test.rb | 38 ++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index f783759b28..9cb6e75395 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -255,7 +255,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 bcd9fd3f40..dbab749540 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -600,6 +600,37 @@ 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 without development test") + system("bundle config set --local with production") + system("bundle config set --local jobs 1") + system("bundle config set --local clean true") + + assert_path_exists(File.join(dir, ".bundle", "config")) + + capture_subprocess_io do + system("bundle install") + + env = run_script(dir) + + assert_equal("true", env["BUNDLE_CLEAN"]) + assert_equal("1", env["BUNDLE_JOBS"]) + assert_equal("production", env["BUNDLE_WITH"]) + assert_equal("development:test", env["BUNDLE_WITHOUT"]) + end + end + end + end + end + private def with_default_external_encoding(encoding, &block) @@ -629,12 +660,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 @@ -658,7 +692,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"]