From 7f6ef77d0e12b898a366dd907e4c4f3434fcb9a6 Mon Sep 17 00:00:00 2001 From: Doug Hogan Date: Sat, 27 Jul 2019 07:21:36 -0700 Subject: [PATCH] Address PR comments: remove test and use return ... if --- Library/Homebrew/cask/cmd/upgrade.rb | 18 ++++++++---------- Library/Homebrew/cmd/upgrade.rb | 12 +++++------- Library/Homebrew/test/cmd/upgrade_spec.rb | 13 ------------- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index 948d97e74a..77529012b9 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -42,16 +42,14 @@ module Cask .map { |(old_cask, new_cask)| "#{new_cask.full_name} #{old_cask.version} -> #{new_cask.version}" } .join(", ") - if dry_run? - puts "Dry run: did not upgrade anything." - else - upgradable_casks.each do |(old_cask, new_cask)| - begin - upgrade_cask(old_cask, new_cask) - rescue CaskError => e - caught_exceptions << e - next - end + return puts "Dry run: did not upgrade anything." if dry_run? + + upgradable_casks.each do |(old_cask, new_cask)| + begin + upgrade_cask(old_cask, new_cask) + rescue CaskError => e + caught_exceptions << e + next end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 854035dd95..f0acf672fb 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -106,15 +106,13 @@ module Homebrew puts formulae_upgrades.join(", ") end - if args.dry_run? - puts "Dry run: did not upgrade anything." - else - upgrade_formulae(formulae_to_install) + return puts "Dry run: did not upgrade anything." if args.dry_run? - check_dependents(formulae_to_install) + upgrade_formulae(formulae_to_install) - Homebrew.messages.display_messages - end + check_dependents(formulae_to_install) + + Homebrew.messages.display_messages end def upgrade_formulae(formulae_to_install) diff --git a/Library/Homebrew/test/cmd/upgrade_spec.rb b/Library/Homebrew/test/cmd/upgrade_spec.rb index a4e13ccb71..9f139fc059 100644 --- a/Library/Homebrew/test/cmd/upgrade_spec.rb +++ b/Library/Homebrew/test/cmd/upgrade_spec.rb @@ -16,17 +16,4 @@ describe "brew upgrade", :integration_test do expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist end - - it "can do a dry run upgrade" do - setup_test_formula "testball" - (HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath - - expect { brew "upgrade", "--dry-run" } - .to output(/Dry run: did not upgrade anything/).to_stdout - .and not_to_output.to_stderr - .and be_a_success - - expect(HOMEBREW_CELLAR/"testball/0.1").not_to exist - expect(HOMEBREW_CELLAR/"testball/0.0.1").to be_a_directory - end end