From 054ce75872c232dad4d5d5f5ce4004d13c0762f6 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 28 Aug 2023 16:12:19 -0400 Subject: [PATCH 1/2] Prevent bundle check from printing to stdout --- lib/ruby_lsp/setup_bundler.rb | 2 +- test/setup_bundler_test.rb | 33 ++++++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 544e156e2..71c417ea7 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -179,7 +179,7 @@ def run_bundle_install(bundle_gemfile = @gemfile) if should_bundle_install? # Install gems using the custom bundle - command << "bundle check || bundle install " + command << "(bundle check || bundle install) " else # If ruby-lsp or debug are not in the Gemfile, try to update them to the latest version command << "bundle update " diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index a20a93449..ff163c60b 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -6,14 +6,14 @@ class SetupBundlerTest < Minitest::Test def test_does_nothing_if_both_ruby_lsp_and_debug_are_in_the_bundle - Object.any_instance.expects(:system).with(bundle_env, "bundle check || bundle install 1>&2") + Object.any_instance.expects(:system).with(bundle_env, "(bundle check || bundle install) 1>&2") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({ "ruby-lsp" => true, "debug" => true }) run_script refute_path_exists(".ruby-lsp") end def test_removes_ruby_lsp_folder_if_both_gems_were_added_to_the_bundle - Object.any_instance.expects(:system).with(bundle_env, "bundle check || bundle install 1>&2") + Object.any_instance.expects(:system).with(bundle_env, "(bundle check || bundle install) 1>&2") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({ "ruby-lsp" => true, "debug" => true }) FileUtils.mkdir(".ruby-lsp") run_script @@ -23,7 +23,7 @@ def test_removes_ruby_lsp_folder_if_both_gems_were_added_to_the_bundle end def test_creates_custom_bundle - Object.any_instance.expects(:system).with(bundle_env(".ruby-lsp/Gemfile"), "bundle check || bundle install 1>&2") + Object.any_instance.expects(:system).with(bundle_env(".ruby-lsp/Gemfile"), "(bundle check || bundle install) 1>&2") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}).at_least_once run_script @@ -77,7 +77,7 @@ def test_changing_lockfile_causes_custom_bundle_to_be_rebuilt # instead, which re-locks and adds the ruby-lsp Object.any_instance.expects(:system).with( bundle_env(".ruby-lsp/Gemfile"), - "bundle check || bundle install 1>&2", + "(bundle check || bundle install) 1>&2", ) Bundler.with_unbundled_env do run_script @@ -146,7 +146,7 @@ def test_does_only_updates_every_4_hours capture_subprocess_io do Object.any_instance.expects(:system).with( bundle_env(".ruby-lsp/Gemfile"), - "bundle check || bundle install 1>&2", + "(bundle check || bundle install) 1>&2", ) Bundler.with_unbundled_env do @@ -160,7 +160,7 @@ def test_does_only_updates_every_4_hours 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") + Object.any_instance.expects(:system).with(bundle_env(".ruby-lsp/Gemfile"), "(bundle check || bundle install) 1>&2") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}).at_least_once run_script(expected_path: File.expand_path("vendor/bundle", Dir.pwd)) ensure @@ -176,7 +176,7 @@ def test_creates_custom_bundle_if_no_gemfile bundle_gemfile = Pathname.new(".ruby-lsp").expand_path(Dir.pwd) + "Gemfile" Object.any_instance.expects(:system).with( bundle_env(bundle_gemfile.to_s), - "bundle check || bundle install 1>&2", + "(bundle check || bundle install) 1>&2", ) Bundler.with_unbundled_env do @@ -239,7 +239,7 @@ def test_does_nothing_if_both_ruby_lsp_and_debug_are_gemspec_dependencies FileUtils.touch(File.join(dir, "Gemfile.lock")) Bundler.with_unbundled_env do - Object.any_instance.expects(:system).with(bundle_env, "bundle check || bundle install 1>&2") + Object.any_instance.expects(:system).with(bundle_env, "(bundle check || bundle install) 1>&2") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({}) run_script end @@ -255,7 +255,7 @@ def test_creates_custom_bundle_with_specified_branch bundle_gemfile = Pathname.new(".ruby-lsp").expand_path(Dir.pwd) + "Gemfile" Object.any_instance.expects(:system).with( bundle_env(bundle_gemfile.to_s), - "bundle check || bundle install 1>&2", + "(bundle check || bundle install) 1>&2", ) Bundler.with_unbundled_env do @@ -270,6 +270,21 @@ def test_creates_custom_bundle_with_specified_branch end end + def test_does_not_print_to_stdout + # Create a temporary directory with no Gemfile or Gemfile.lock + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + stdout, _stderr = capture_subprocess_io do + Bundler.with_unbundled_env do + run_script + end + end + + assert_empty(stdout) + end + end + end + private # This method runs the script and then immediately unloads it. This allows us to make assertions against the effects From ea8a71382a8da449db4086e5881db1a590bb730b Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 28 Aug 2023 16:13:58 -0400 Subject: [PATCH 2/2] Bump version to v0.9.1 --- Gemfile.lock | 2 +- VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8ff82b2fa..c31461c57 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - ruby-lsp (0.9.0) + ruby-lsp (0.9.1) language_server-protocol (~> 3.17.0) sorbet-runtime syntax_tree (>= 6.1.1, < 7) diff --git a/VERSION b/VERSION index ac39a106c..f374f6662 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.9.0 +0.9.1