Skip to content

Commit

Permalink
Prevent test suite from modifying contributors' Bundler settings (#2083)
Browse files Browse the repository at this point in the history
* Prevent test suite from modifying contributors' Bundler settings

* Fix test
  • Loading branch information
natematykiewicz authored and andyw8 committed May 29, 2024
1 parent 500044f commit 69f6c81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
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/**/*.rb")
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

0 comments on commit 69f6c81

Please sign in to comment.