Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 committed Jul 11, 2024
1 parent ccdb0a6 commit d9a3072
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d9a3072

Please sign in to comment.