Skip to content

Commit

Permalink
Fix bundler env
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezhny committed Sep 23, 2024
1 parent 95c35f6 commit 82e4077
Show file tree
Hide file tree
Showing 2 changed files with 40 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 @@ -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

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

0 comments on commit 82e4077

Please sign in to comment.