diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index c2b3e0ec06..f842650129 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -483,6 +483,37 @@ def test_ensures_lockfile_remotes_are_relative_to_default_gemfile end def test_ruby_lsp_rails_is_automatically_included_in_rails_apps + Dir.mktmpdir do |dir| + FileUtils.mkdir("#{dir}/config") + FileUtils.cp("test/fixtures/rails_application.rb", "#{dir}/config/application.rb") + Dir.chdir(dir) do + File.write(File.join(dir, "Gemfile"), <<~GEMFILE) + source "https://rubygems.org" + gem "rails" + GEMFILE + + capture_subprocess_io do + Bundler.with_unbundled_env do + # Run bundle install to generate the lockfile + system("bundle install") + end + end + + Object.any_instance.expects(:system).with( + bundle_env(".ruby-lsp/Gemfile"), + "(bundle check || bundle install) 1>&2", + ).returns(true) + Bundler.with_unbundled_env do + run_script + end + + assert_path_exists(".ruby-lsp/Gemfile") + assert_match('gem "ruby-lsp-rails"', File.read(".ruby-lsp/Gemfile")) + end + end + end + + def test_ruby_lsp_rails_detection_handles_lang_from_environment original_encoding = Encoding.default_external Encoding.default_external = "us-ascii"