Skip to content

Commit

Permalink
Fix bundler env (#2595)
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezhny authored Sep 23, 2024
1 parent 54952fa commit 81f08de
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 31 additions & 1 deletion test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand Down

0 comments on commit 81f08de

Please sign in to comment.