Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various style issues under newer RuboCop #1271

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/bundle/brew_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/bundle/lister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/bundle/locker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions spec/bundle/cask_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
21 changes: 10 additions & 11 deletions spec/bundle/commands/check_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions spec/bundle/commands/cleanup_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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?
Expand Down
3 changes: 1 addition & 2 deletions spec/bundle/commands/exec_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'")

Expand Down
42 changes: 14 additions & 28 deletions spec/bundle/commands/install_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,36 +48,25 @@
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)

expect { described_class.run }.to raise_error(SystemExit)
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)
Expand Down
6 changes: 2 additions & 4 deletions spec/bundle/dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
3 changes: 1 addition & 2 deletions spec/bundle/locker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading