diff --git a/lib/bundle/brew_dumper.rb b/lib/bundle/brew_dumper.rb index 1bef9af60..e92c45820 100644 --- a/lib/bundle/brew_dumper.rb +++ b/lib/bundle/brew_dumper.rb @@ -165,18 +165,18 @@ def formula_to_hash(formula) any_version_installed?: formula.any_version_installed?, args: Array(args).uniq, version: version, - installed_as_dependency?: (installed_as_dependency || false), - installed_on_request?: (installed_on_request || false), + installed_as_dependency?: installed_as_dependency || false, + installed_on_request?: installed_on_request || false, dependencies: runtime_dependencies, build_dependencies: formula.deps.select(&:build?).map(&:name).uniq, conflicts_with: formula.conflicts.map(&:name), - pinned?: (formula.pinned? || false), - outdated?: (formula.outdated? || false), + pinned?: formula.pinned? || false, + outdated?: formula.outdated? || false, link?: link, - poured_from_bottle?: (poured_from_bottle || false), - bottle: (bottle_hash || false), - bottled: (bottled || false), - official_tap: (formula.tap&.official? || false), + poured_from_bottle?: poured_from_bottle || false, + bottle: bottle_hash || false, + bottled: bottled || false, + official_tap: formula.tap&.official? || false, } end private_class_method :formula_to_hash diff --git a/lib/bundle/dsl.rb b/lib/bundle/dsl.rb index 7a8267cd8..5742c36ba 100644 --- a/lib/bundle/dsl.rb +++ b/lib/bundle/dsl.rb @@ -103,7 +103,7 @@ def self.sanitize_brew_name(name) user = Regexp.last_match(1) repo = Regexp.last_match(2) name = Regexp.last_match(3) - "#{user}/#{repo.sub(/homebrew-/, "")}/#{name}" + "#{user}/#{repo.sub("homebrew-", "")}/#{name}" else name end diff --git a/lib/bundle/lister.rb b/lib/bundle/lister.rb index be29b4c67..e35f87e7f 100644 --- a/lib/bundle/lister.rb +++ b/lib/bundle/lister.rb @@ -24,6 +24,8 @@ def self.show?(type, all: false, casks: false, taps: false, mas: false, whalebre return true if vscode && type == :vscode return true if brews && type == :brew return true if type == :brew && !casks && !taps && !mas && !whalebrew && !vscode + + false end end end diff --git a/lib/bundle/locker.rb b/lib/bundle/locker.rb index e84553ce5..1bd0608bc 100644 --- a/lib/bundle/locker.rb +++ b/lib/bundle/locker.rb @@ -108,7 +108,7 @@ def brew_list(name) return @brew_list[name] if @brew_list.key?(name) @brew_list[name] ||= Bundle::BrewDumper.formulae_by_name(name) - &.slice(:version, :bottle) + &.slice(:version, :bottle) end def cask_list diff --git a/spec/bundle/cask_installer_spec.rb b/spec/bundle/cask_installer_spec.rb index fc34cad62..2cff657c7 100644 --- a/spec/bundle/cask_installer_spec.rb +++ b/spec/bundle/cask_installer_spec.rb @@ -16,8 +16,8 @@ describe ".cask_installed_and_up_to_date?" do it "returns result" do described_class.reset! - allow(described_class).to receive(:installed_casks).and_return(["foo", "baz"]) - allow(described_class).to receive(:outdated_casks).and_return(["baz"]) + allow(described_class).to receive_messages(installed_casks: ["foo", "baz"], + outdated_casks: ["baz"]) expect(described_class.cask_installed_and_up_to_date?("foo")).to be(true) expect(described_class.cask_installed_and_up_to_date?("baz")).to be(false) end @@ -59,8 +59,8 @@ context "when cask is outdated" do before do - allow(described_class).to receive(:installed_casks).and_return(["google-chrome"]) - allow(described_class).to receive(:outdated_casks).and_return(["google-chrome"]) + allow(described_class).to receive_messages(installed_casks: ["google-chrome"], + outdated_casks: ["google-chrome"]) end it "upgrades" do @@ -74,8 +74,7 @@ context "when cask is outdated and uses auto-update" do before do - allow(Bundle::CaskDumper).to receive(:cask_names).and_return(["opera"]) - allow(Bundle::CaskDumper).to receive(:outdated_cask_names).and_return([]) + allow(Bundle::CaskDumper).to receive_messages(cask_names: ["opera"], outdated_cask_names: []) allow(Bundle::CaskDumper).to receive(:outdated_cask_names).with(greedy: true).and_return(["opera"]) end diff --git a/spec/bundle/commands/check_command_spec.rb b/spec/bundle/commands/check_command_spec.rb index ce3891d3a..450293fde 100644 --- a/spec/bundle/commands/check_command_spec.rb +++ b/spec/bundle/commands/check_command_spec.rb @@ -18,11 +18,11 @@ it "does not raise an error" do allow_any_instance_of(Pathname).to receive(:read).and_return("") nothing = [] - allow(Bundle::Checker).to receive(:casks_to_install).and_return(nothing) - allow(Bundle::Checker).to receive(:formulae_to_install).and_return(nothing) - allow(Bundle::Checker).to receive(:apps_to_install).and_return(nothing) - allow(Bundle::Checker).to receive(:taps_to_tap).and_return(nothing) - allow(Bundle::Checker).to receive(:extensions_to_install).and_return(nothing) + allow(Bundle::Checker).to receive_messages(casks_to_install: nothing, + formulae_to_install: nothing, + apps_to_install: nothing, + taps_to_tap: nothing, + extensions_to_install: nothing) expect { do_check }.not_to raise_error end end @@ -94,8 +94,7 @@ before do Bundle::Checker.reset! allow(Bundle::Checker::MacAppStoreChecker).to receive(:installed_and_up_to_date?).and_return(false) - allow(Bundle::BrewInstaller).to receive(:installed_formulae).and_return(["abc", "def"]) - allow(Bundle::BrewInstaller).to receive(:upgradable_formulae).and_return([]) + allow(Bundle::BrewInstaller).to receive_messages(installed_formulae: ["abc", "def"], upgradable_formulae: []) allow(Bundle::BrewServices).to receive(:started?).with("abc").and_return(true) allow(Bundle::BrewServices).to receive(:started?).with("def").and_return(false) end @@ -219,10 +218,10 @@ context "when there are formulae to install" do before do allow_any_instance_of(Pathname).to receive(:read).and_return("") - allow(Bundle::Checker).to receive(:taps_to_tap).and_return([]) - allow(Bundle::Checker).to receive(:casks_to_install).and_return([]) - allow(Bundle::Checker).to receive(:apps_to_install).and_return([]) - allow(Bundle::Checker).to receive(:formulae_to_install).and_return(["one"]) + allow(Bundle::Checker).to receive_messages(taps_to_tap: [], + casks_to_install: [], + apps_to_install: [], + formulae_to_install: ["one"]) end it "does not start formulae" do diff --git a/spec/bundle/commands/cleanup_command_spec.rb b/spec/bundle/commands/cleanup_command_spec.rb index f77f5faf5..c48c6037c 100644 --- a/spec/bundle/commands/cleanup_command_spec.rb +++ b/spec/bundle/commands/cleanup_command_spec.rb @@ -81,10 +81,10 @@ context "when there are no formulae to uninstall and no taps to untap" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return([]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: [], + formulae_to_uninstall: [], + taps_to_untap: [], + vscode_extensions_to_uninstall: []) end it "does nothing" do @@ -97,10 +97,10 @@ context "when there are casks to uninstall" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return(%w[a b]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], + formulae_to_uninstall: [], + taps_to_untap: [], + vscode_extensions_to_uninstall: []) end it "uninstalls casks" do @@ -113,10 +113,10 @@ context "when there are casks to zap" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return(%w[a b]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], + formulae_to_uninstall: [], + taps_to_untap: [], + vscode_extensions_to_uninstall: []) end it "uninstalls casks" do @@ -129,10 +129,10 @@ context "when there are formulae to uninstall" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return([]) - allow(described_class).to receive(:formulae_to_uninstall).and_return(%w[a b]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: [], + formulae_to_uninstall: %w[a b], + taps_to_untap: [], + vscode_extensions_to_uninstall: []) end it "uninstalls formulae" do @@ -145,10 +145,10 @@ context "when there are taps to untap" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return([]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return(%w[a b]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: [], + formulae_to_uninstall: [], + taps_to_untap: %w[a b], + vscode_extensions_to_uninstall: []) end it "untaps taps" do @@ -161,10 +161,10 @@ context "when there are VSCode extensions to uninstall" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return([]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return(%w[GitHub.codespaces]) + allow(described_class).to receive_messages(casks_to_uninstall: [], + formulae_to_uninstall: [], + taps_to_untap: [], + vscode_extensions_to_uninstall: %w[GitHub.codespaces]) end it "uninstalls extensions" do @@ -177,10 +177,10 @@ context "when there are casks and formulae to uninstall and taps to untap but without passing `--force`" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return(%w[a b]) - allow(described_class).to receive(:formulae_to_uninstall).and_return(%w[a b]) - allow(described_class).to receive(:taps_to_untap).and_return(%w[a b]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return(%w[a b]) + allow(described_class).to receive_messages(casks_to_uninstall: %w[a b], + formulae_to_uninstall: %w[a b], + taps_to_untap: %w[a b], + vscode_extensions_to_uninstall: %w[a b]) end it "lists casks, formulae and taps" do @@ -196,10 +196,10 @@ context "when there is brew cleanup output" do before do described_class.reset! - allow(described_class).to receive(:casks_to_uninstall).and_return([]) - allow(described_class).to receive(:formulae_to_uninstall).and_return([]) - allow(described_class).to receive(:taps_to_untap).and_return([]) - allow(described_class).to receive(:vscode_extensions_to_uninstall).and_return([]) + allow(described_class).to receive_messages(casks_to_uninstall: [], + formulae_to_uninstall: [], + taps_to_untap: [], + vscode_extensions_to_uninstall: []) end def sane? diff --git a/spec/bundle/commands/exec_command_spec.rb b/spec/bundle/commands/exec_command_spec.rb index 116d34282..68166d0c2 100644 --- a/spec/bundle/commands/exec_command_spec.rb +++ b/spec/bundle/commands/exec_command_spec.rb @@ -35,8 +35,7 @@ end it "raises if called with a command that's not on the PATH" do - allow(described_class).to receive(:exec).and_return(nil) - allow(described_class).to receive(:which).and_return(nil) + allow(described_class).to receive_messages(exec: nil, which: nil) allow_any_instance_of(Pathname).to receive(:read) .and_return("brew 'openssl'") diff --git a/spec/bundle/commands/install_command_spec.rb b/spec/bundle/commands/install_command_spec.rb index 447732008..41f5227bc 100644 --- a/spec/bundle/commands/install_command_spec.rb +++ b/spec/bundle/commands/install_command_spec.rb @@ -28,15 +28,12 @@ end it "does not raise an error" do - allow(Bundle::BrewInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::CaskInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::MacAppStoreInstaller).to receive(:preinstall).and_return(true) allow(Bundle::TapInstaller).to receive(:preinstall).and_return(false) allow(Bundle::WhalebrewInstaller).to receive(:preinstall).and_return(false) allow(Bundle::VscodeExtensionInstaller).to receive(:preinstall).and_return(false) - allow(Bundle::BrewInstaller).to receive(:install).and_return(true) - allow(Bundle::CaskInstaller).to receive(:install).and_return(true) - allow(Bundle::MacAppStoreInstaller).to receive(:install).and_return(true) + allow(Bundle::BrewInstaller).to receive_messages(preinstall: true, install: true) + allow(Bundle::CaskInstaller).to receive_messages(preinstall: true, install: true) + allow(Bundle::MacAppStoreInstaller).to receive_messages(preinstall: true, install: true) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) expect { described_class.run }.not_to raise_error end @@ -51,18 +48,12 @@ end it "exits on failures" do - allow(Bundle::BrewInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::CaskInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::MacAppStoreInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::TapInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::WhalebrewInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::VscodeExtensionInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::BrewInstaller).to receive(:install).and_return(false) - allow(Bundle::CaskInstaller).to receive(:install).and_return(false) - allow(Bundle::MacAppStoreInstaller).to receive(:install).and_return(false) - allow(Bundle::TapInstaller).to receive(:install).and_return(false) - allow(Bundle::WhalebrewInstaller).to receive(:install).and_return(false) - allow(Bundle::VscodeExtensionInstaller).to receive(:install).and_return(false) + allow(Bundle::BrewInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::CaskInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::MacAppStoreInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::TapInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::WhalebrewInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::VscodeExtensionInstaller).to receive_messages(preinstall: true, install: false) allow(Bundle::Locker).to receive(:lockfile).and_return(Pathname(__dir__)) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) @@ -70,17 +61,12 @@ end it "skips installs from failed taps" do - allow(Bundle::BrewInstaller).to receive(:preinstall).and_return(true) allow(Bundle::CaskInstaller).to receive(:preinstall).and_return(false) - allow(Bundle::MacAppStoreInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::TapInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::WhalebrewInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::VscodeExtensionInstaller).to receive(:preinstall).and_return(true) - allow(Bundle::TapInstaller).to receive(:install).and_return(false) - allow(Bundle::BrewInstaller).to receive(:install).and_return(true) - allow(Bundle::MacAppStoreInstaller).to receive(:install).and_return(true) - allow(Bundle::WhalebrewInstaller).to receive(:install).and_return(true) - allow(Bundle::VscodeExtensionInstaller).to receive(:install).and_return(true) + allow(Bundle::TapInstaller).to receive_messages(preinstall: true, install: false) + allow(Bundle::BrewInstaller).to receive_messages(preinstall: true, install: true) + allow(Bundle::MacAppStoreInstaller).to receive_messages(preinstall: true, install: true) + allow(Bundle::WhalebrewInstaller).to receive_messages(preinstall: true, install: true) + allow(Bundle::VscodeExtensionInstaller).to receive_messages(preinstall: true, install: true) allow_any_instance_of(Pathname).to receive(:read).and_return(brewfile_contents) expect(Bundle).not_to receive(:system) diff --git a/spec/bundle/dumper_spec.rb b/spec/bundle/dumper_spec.rb index 866a5318b..50515bae4 100644 --- a/spec/bundle/dumper_spec.rb +++ b/spec/bundle/dumper_spec.rb @@ -7,10 +7,8 @@ subject(:dumper) { described_class } before do - allow(Bundle).to receive(:cask_installed?).and_return(true) - allow(Bundle).to receive(:mas_installed?).and_return(false) - allow(Bundle).to receive(:whalebrew_installed?).and_return(false) - allow(Bundle).to receive(:vscode_installed?).and_return(false) + allow(Bundle).to receive_messages(cask_installed?: true, mas_installed?: false, whalebrew_installed?: false, + vscode_installed?: false) Bundle::BrewDumper.reset! Bundle::TapDumper.reset! Bundle::CaskDumper.reset! diff --git a/spec/bundle/locker_spec.rb b/spec/bundle/locker_spec.rb index 05f7ae821..d18be63f9 100644 --- a/spec/bundle/locker_spec.rb +++ b/spec/bundle/locker_spec.rb @@ -124,8 +124,7 @@ context "when on Linux" do before do - allow(OS).to receive(:mac?).and_return(false) - allow(OS).to receive(:linux?).and_return(true) + allow(OS).to receive_messages(mac?: false, linux?: true) end it "returns true" do diff --git a/spec/bundle/mac_app_store_installer_spec.rb b/spec/bundle/mac_app_store_installer_spec.rb index b304b0874..46a8c357f 100644 --- a/spec/bundle/mac_app_store_installer_spec.rb +++ b/spec/bundle/mac_app_store_installer_spec.rb @@ -11,8 +11,7 @@ describe ".app_id_installed_and_up_to_date?" do it "returns result" do - allow(described_class).to receive(:installed_app_ids).and_return([123, 456]) - allow(described_class).to receive(:outdated_app_ids).and_return([456]) + allow(described_class).to receive_messages(installed_app_ids: [123, 456], outdated_app_ids: [456]) expect(described_class.app_id_installed_and_up_to_date?(123)).to be(true) expect(described_class.app_id_installed_and_up_to_date?(456)).to be(false) end @@ -54,8 +53,7 @@ context "when mas is not signed in" do it "outputs an error" do - allow(described_class).to receive(:installed_app_ids).and_return([123]) - allow(described_class).to receive(:outdated_app_ids).and_return([123]) + allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123]) allow(MacOS).to receive(:version).and_return(:big_sur) expect(Kernel).to receive(:system).with("mas account &>/dev/null").and_return(false) expect { described_class.preinstall("foo", 123) }.to raise_error(RuntimeError) @@ -81,8 +79,7 @@ context "when app is outdated" do before do - allow(described_class).to receive(:installed_app_ids).and_return([123]) - allow(described_class).to receive(:outdated_app_ids).and_return([123]) + allow(described_class).to receive_messages(installed_app_ids: [123], outdated_app_ids: [123]) end it "upgrades" do diff --git a/spec/bundle/vscode_extension_installer_spec.rb b/spec/bundle/vscode_extension_installer_spec.rb index 57188c464..056645d58 100644 --- a/spec/bundle/vscode_extension_installer_spec.rb +++ b/spec/bundle/vscode_extension_installer_spec.rb @@ -6,8 +6,7 @@ context "when VSCode is not installed" do before do described_class.reset! - allow(Bundle).to receive(:vscode_installed?).and_return(false) - allow(Bundle).to receive(:cask_installed?).and_return(true) + allow(Bundle).to receive_messages(vscode_installed?: false, cask_installed?: true) end it "tries to install mas" do