Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent test suite from modifying contributors' Bundler settings #2083

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/ruby_indexer/test/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ def test_indexables_includes_project_files
end

def test_indexables_avoids_duplicates_if_bundle_path_is_inside_project
Bundler.settings.set_global("path", "vendor/bundle")
config = Configuration.new
Bundler.settings.temporary(path: "vendor/bundle") do
config = Configuration.new

assert_includes(config.instance_variable_get(:@excluded_patterns), "#{Dir.pwd}/vendor/bundle/**/*.rb")
ensure
Bundler.settings.set_global("path", nil)
assert_includes(config.instance_variable_get(:@excluded_patterns), "#{Dir.pwd}/vendor/bundle/**/*")
end
end

def test_indexables_does_not_include_gems_own_installed_files
Expand Down
33 changes: 15 additions & 18 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,15 @@ def test_does_only_updates_every_4_hours
end

def test_uses_absolute_bundle_path_for_bundle_install
Bundler.settings.set_global("path", "vendor/bundle")
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))
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
ensure
# We need to revert the changes to the bundler config or else this actually changes ~/.bundle/config
Bundler.settings.set_global("path", nil)
FileUtils.rm_r(".ruby-lsp")
end

Expand Down Expand Up @@ -366,19 +365,17 @@ def test_returns_bundle_app_config_if_there_is_local_config
Dir.chdir(dir) do
bundle_gemfile = Pathname.new(".ruby-lsp").expand_path(Dir.pwd) + "Gemfile"
Bundler.with_unbundled_env do
Bundler.settings.set_local("without", "production")
Object.any_instance.expects(:system).with(
bundle_env(bundle_gemfile.to_s),
"(bundle check || bundle install) 1>&2",
).returns(true)
Bundler.settings.temporary(without: "production") do
Object.any_instance.expects(:system).with(
bundle_env(bundle_gemfile.to_s),
"(bundle check || bundle install) 1>&2",
).returns(true)

run_script
run_script
end
end
end
end
ensure
# CI uses a local bundle config and we don't want to delete that
FileUtils.rm_r(File.join(Dir.pwd, ".bundle")) unless ENV["CI"]
end

def test_custom_bundle_uses_alternative_gemfiles
Expand Down
Loading