Skip to content

Commit

Permalink
Prevent bundle check from printing to stdout (#942)
Browse files Browse the repository at this point in the history
* Prevent bundle check from printing to stdout

* Bump version to v0.9.1
  • Loading branch information
vinistock authored Aug 28, 2023
1 parent e4f0967 commit 5cb9407
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.0
0.9.1
2 changes: 1 addition & 1 deletion lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
33 changes: 24 additions & 9 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5cb9407

Please sign in to comment.