Merge pull request #14877 from issyl0/rubocop-layout/multiline-method-indentation

rubocop: Enable `Layout/MultilineMethodCallIndentation` & fix offenses
This commit is contained in:
Issy Long 2023-03-06 12:18:29 +00:00 committed by GitHub
commit 984e8d1503
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 125 additions and 99 deletions

View File

@ -10,11 +10,6 @@ Homebrew/MoveToExtendOS:
- "{extend,test,requirements}/**/*" - "{extend,test,requirements}/**/*"
- "os.rb" - "os.rb"
# make rspec formatting more flexible
Layout/MultilineMethodCallIndentation:
Exclude:
- "**/*_spec.rb"
Naming/PredicateName: Naming/PredicateName:
AllowedMethods: AllowedMethods:
- is_32_bit? - is_32_bit?

View File

@ -232,10 +232,9 @@ describe Cask::Cask, :cask do
context "when loaded from json file" do context "when loaded from json file" do
it "returns expected hash" do it "returns expected hash" do
expect(Homebrew::API::Cask).not_to receive(:fetch_source) expect(Homebrew::API::Cask).not_to receive(:fetch_source)
hash = Cask::CaskLoader::FromAPILoader hash = Cask::CaskLoader::FromAPILoader.new(
.new("everything", from_json: JSON.parse(expected_json)) "everything", from_json: JSON.parse(expected_json)
.load(config: nil) ).load(config: nil).to_h
.to_h
expect(hash).to be_a(Hash) expect(hash).to be_a(Hash)
expect(JSON.pretty_generate(hash)).to eq(expected_json) expect(JSON.pretty_generate(hash)).to eq(expected_json)

View File

@ -28,7 +28,8 @@ describe Cask::Cmd::Install, :cask do
it "recognizes the --appdir flag" do it "recognizes the --appdir flag" do
appdir = mktmpdir appdir = mktmpdir
expect(Cask::CaskLoader).to receive(:load).with("local-caffeine", any_args) expect(Cask::CaskLoader).to receive(:load)
.with("local-caffeine", any_args)
.and_wrap_original { |f, *args| .and_wrap_original { |f, *args|
caffeine = f.call(*args) caffeine = f.call(*args)
expect(caffeine.config.appdir).to eq appdir expect(caffeine.config.appdir).to eq appdir
@ -41,7 +42,8 @@ describe Cask::Cmd::Install, :cask do
it "recognizes the --appdir flag from HOMEBREW_CASK_OPTS" do it "recognizes the --appdir flag from HOMEBREW_CASK_OPTS" do
appdir = mktmpdir appdir = mktmpdir
expect(Cask::CaskLoader).to receive(:load).with("local-caffeine", any_args) expect(Cask::CaskLoader).to receive(:load)
.with("local-caffeine", any_args)
.and_wrap_original { |f, *args| .and_wrap_original { |f, *args|
caffeine = f.call(*args) caffeine = f.call(*args)
expect(caffeine.config.appdir).to eq appdir expect(caffeine.config.appdir).to eq appdir
@ -57,7 +59,8 @@ describe Cask::Cmd::Install, :cask do
global_appdir = mktmpdir global_appdir = mktmpdir
appdir = mktmpdir appdir = mktmpdir
expect(Cask::CaskLoader).to receive(:load).with("local-caffeine", any_args) expect(Cask::CaskLoader).to receive(:load)
.with("local-caffeine", any_args)
.and_wrap_original { |f, *args| .and_wrap_original { |f, *args|
caffeine = f.call(*args) caffeine = f.call(*args)
expect(caffeine.config.appdir).to eq appdir expect(caffeine.config.appdir).to eq appdir

View File

@ -26,7 +26,7 @@ describe Cask::Cmd::Uninstall, :cask do
it "shows an error when a Cask is provided that's not installed" do it "shows an error when a Cask is provided that's not installed" do
expect { described_class.run("local-caffeine") } expect { described_class.run("local-caffeine") }
.to raise_error(Cask::CaskNotInstalledError, /is not installed/) .to raise_error(Cask::CaskNotInstalledError, /is not installed/)
end end
it "tries anyway on a non-present Cask when --force is given" do it "tries anyway on a non-present Cask when --force is given" do
@ -63,7 +63,7 @@ describe Cask::Cmd::Uninstall, :cask do
cask.config.appdir.join("MyFancyApp.app").rmtree cask.config.appdir.join("MyFancyApp.app").rmtree
expect { described_class.run("with-uninstall-script-app") } expect { described_class.run("with-uninstall-script-app") }
.to raise_error(Cask::CaskError, /uninstall script .* does not exist/) .to raise_error(Cask::CaskError, /uninstall script .* does not exist/)
expect(cask).to be_installed expect(cask).to be_installed

View File

@ -41,14 +41,16 @@ describe CompilerSelector do
it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
allow(Formulary).to receive(:factory).with("gcc") allow(Formulary).to receive(:factory)
.with("gcc")
.and_return(instance_double(Formula, version: Version.new("6.0"))) .and_return(instance_double(Formula, version: Version.new("6.0")))
expect(selector.compiler).to eq("gcc-6") expect(selector.compiler).to eq("gcc-6")
end end
it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
allow(Formulary).to receive(:factory).with("gcc@11") allow(Formulary).to receive(:factory)
.with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0"))) .and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-5") expect(selector.compiler).to eq("gcc-5")
end end
@ -57,7 +59,8 @@ describe CompilerSelector do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
software_spec.fails_with(gcc: "5") software_spec.fails_with(gcc: "5")
software_spec.fails_with(gcc: "7") software_spec.fails_with(gcc: "7")
allow(Formulary).to receive(:factory).with("gcc@11") allow(Formulary).to receive(:factory)
.with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0"))) .and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-6") expect(selector.compiler).to eq("gcc-6")
end end
@ -65,7 +68,8 @@ describe CompilerSelector do
it "returns gcc-7 if gcc formula offers gcc-5 and fails with gcc <= 6 on linux", :needs_linux do it "returns gcc-7 if gcc formula offers gcc-5 and fails with gcc <= 6 on linux", :needs_linux do
software_spec.fails_with(:clang) software_spec.fails_with(:clang)
software_spec.fails_with(:gcc) { version "6" } software_spec.fails_with(:gcc) { version "6" }
allow(Formulary).to receive(:factory).with("gcc@11") allow(Formulary).to receive(:factory)
.with("gcc@11")
.and_return(instance_double(Formula, version: Version.new("5.0"))) .and_return(instance_double(Formula, version: Version.new("5.0")))
expect(selector.compiler).to eq("gcc-7") expect(selector.compiler).to eq("gcc-7")
end end

View File

@ -86,6 +86,8 @@ describe "brew bottle" do
system "git", "commit", "-m", "testball 0.1" system "git", "commit", "-m", "testball 0.1"
end end
# RuboCop would align the `.and` with `.to_stdout` which is too floaty.
# rubocop:disable Layout/MultilineMethodCallIndentation
expect { expect {
brew "bottle", brew "bottle",
"--merge", "--merge",
@ -105,6 +107,7 @@ describe "brew bottle" do
EOS EOS
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
# rubocop:enable Layout/MultilineMethodCallIndentation
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula class Testball < Formula
@ -153,6 +156,8 @@ describe "brew bottle" do
system "git", "commit", "-m", "testball 0.1" system "git", "commit", "-m", "testball 0.1"
end end
# RuboCop would align the `.and` with `.to_stdout` which is too floaty.
# rubocop:disable Layout/MultilineMethodCallIndentation
expect { expect {
brew "bottle", brew "bottle",
"--merge", "--merge",
@ -172,6 +177,7 @@ describe "brew bottle" do
EOS EOS
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
# rubocop:enable Layout/MultilineMethodCallIndentation
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula class Testball < Formula
@ -218,6 +224,8 @@ describe "brew bottle" do
system "git", "commit", "-m", "testball 0.1" system "git", "commit", "-m", "testball 0.1"
end end
# RuboCop would align the `.and` with `.to_stdout` which is too floaty.
# rubocop:disable Layout/MultilineMethodCallIndentation
expect { expect {
brew "bottle", brew "bottle",
"--merge", "--merge",
@ -239,6 +247,7 @@ describe "brew bottle" do
EOS EOS
.and not_to_output.to_stderr .and not_to_output.to_stderr
.and be_a_success .and be_a_success
# rubocop:enable Layout/MultilineMethodCallIndentation
expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS expect((core_tap.path/"Formula/testball.rb").read).to eq <<~EOS
class Testball < Formula class Testball < Formula

View File

@ -20,12 +20,13 @@ describe CurlGitHubPackagesDownloadStrategy do
end end
it "calls curl with anonymous authentication headers" do it "calls curl with anonymous authentication headers" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("--header", "Authorization: Bearer QQ==")), /curl/,
) hash_including(args: array_including_cons("--header", "Authorization: Bearer QQ==")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -34,12 +35,13 @@ describe CurlGitHubPackagesDownloadStrategy do
let(:authorization) { "Bearer dead-beef-cafe" } let(:authorization) { "Bearer dead-beef-cafe" }
it "calls curl with the provided header value" do it "calls curl with the provided header value" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("--header", "Authorization: #{authorization}")), /curl/,
) hash_including(args: array_including_cons("--header", "Authorization: #{authorization}")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end

View File

@ -29,12 +29,13 @@ describe CurlPostDownloadStrategy do
} }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("-d", "form=data").and(array_including_cons("-d", "is=good"))), /curl/,
) hash_including(args: array_including_cons("-d", "form=data").and(array_including_cons("-d", "is=good"))),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -44,12 +45,13 @@ describe CurlPostDownloadStrategy do
let(:specs) { { using: :post } } let(:specs) { { using: :post } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("-X", "POST")), /curl/,
) hash_including(args: array_including_cons("-X", "POST")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end

View File

@ -42,12 +42,13 @@ describe CurlDownloadStrategy do
let(:specs) { { user_agent: "Mozilla/25.0.1" } } let(:specs) { { user_agent: "Mozilla/25.0.1" } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("--user-agent", "Mozilla/25.0.1")), /curl/,
) hash_including(args: array_including_cons("--user-agent", "Mozilla/25.0.1")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -59,15 +60,16 @@ describe CurlDownloadStrategy do
let(:specs) { { user_agent: :fake } } let(:specs) { { user_agent: :fake } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons( /curl/,
"--user-agent", hash_including(args: array_including_cons(
a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/), "--user-agent",
)), a_string_matching(/Mozilla.*Mac OS X 10.*AppleWebKit/),
) )),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -84,12 +86,13 @@ describe CurlDownloadStrategy do
} }
it "adds the appropriate curl args and does not URL-encode the cookies" do it "adds the appropriate curl args and does not URL-encode the cookies" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("-b", "coo=k/e;mon=ster")), /curl/,
) hash_including(args: array_including_cons("-b", "coo=k/e;mon=ster")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -99,12 +102,13 @@ describe CurlDownloadStrategy do
let(:specs) { { referer: "https://somehost/also" } } let(:specs) { { referer: "https://somehost/also" } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("-e", "https://somehost/also")), /curl/,
) hash_including(args: array_including_cons("-e", "https://somehost/also")),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -116,12 +120,15 @@ describe CurlDownloadStrategy do
let(:specs) { { headers: ["foo", "bar"] } } let(:specs) { { headers: ["foo", "bar"] } }
it "adds the appropriate curl args" do it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("--header", "foo").and(array_including_cons("--header", "bar"))), /curl/,
) hash_including(
.at_least(:once) args: array_including_cons("--header", "foo").and(array_including_cons("--header", "bar")),
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) ),
)
.at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -132,12 +139,13 @@ describe CurlDownloadStrategy do
context "with an asset hosted under example.com" do context "with an asset hosted under example.com" do
it "leaves the URL unchanged" do it "leaves the URL unchanged" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons(url)), /curl/,
) hash_including(args: array_including_cons(url)),
.at_least(:once) )
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil)) .at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch strategy.fetch
end end
@ -149,12 +157,13 @@ describe CurlDownloadStrategy do
let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) }
it "rewrites the URL correctly" do it "rewrites the URL correctly" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), /curl/,
) hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")),
.at_least(:once) )
.and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: [])) .at_least(:once)
.and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: []))
strategy.fetch strategy.fetch
end end
@ -166,12 +175,13 @@ describe CurlDownloadStrategy do
let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) } let(:status) { instance_double(Process::Status, success?: true, exitstatus: 0) }
it "rewrites the URL correctly" do it "rewrites the URL correctly" do
expect(strategy).to receive(:system_command).with( expect(strategy).to receive(:system_command)
/curl/, .with(
hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")), /curl/,
) hash_including(args: array_including_cons("#{artifact_domain}/#{resource_path}")),
.at_least(:once) )
.and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: [])) .at_least(:once)
.and_return(SystemCommand::Result.new(["curl"], [""], status, secrets: []))
strategy.fetch strategy.fetch
end end

View File

@ -191,7 +191,8 @@ describe Resource do
fn = instance_double(Pathname, file?: true, basename: "foo") fn = instance_double(Pathname, file?: true, basename: "foo")
checksum = resource.sha256(TEST_SHA256) checksum = resource.sha256(TEST_SHA256)
expect(fn).to receive(:verify_checksum).with(checksum) expect(fn).to receive(:verify_checksum)
.with(checksum)
.and_raise(ChecksumMismatchError.new(fn, checksum, Object.new)) .and_raise(ChecksumMismatchError.new(fn, checksum, Object.new))
expect { expect {

View File

@ -62,7 +62,7 @@ describe Utils::Autoremove do
it "filters out runtime dependencies" do it "filters out runtime dependencies" do
allow(tab_from_keg).to receive(:poured_from_bottle).and_return(true) allow(tab_from_keg).to receive(:poured_from_bottle).and_return(true)
expect(described_class.send(:formulae_with_no_formula_dependents, formulae)) expect(described_class.send(:formulae_with_no_formula_dependents, formulae))
.to eq([formula_with_deps, formula_is_build_dep]) .to eq([formula_with_deps, formula_is_build_dep])
end end
end end
@ -70,7 +70,7 @@ describe Utils::Autoremove do
it "filters out runtime and build dependencies" do it "filters out runtime and build dependencies" do
allow(tab_from_keg).to receive(:poured_from_bottle).and_return(false) allow(tab_from_keg).to receive(:poured_from_bottle).and_return(false)
expect(described_class.send(:formulae_with_no_formula_dependents, formulae)) expect(described_class.send(:formulae_with_no_formula_dependents, formulae))
.to eq([formula_with_deps]) .to eq([formula_with_deps])
end end
end end
end end
@ -85,13 +85,13 @@ describe Utils::Autoremove do
specify "installed on request" do specify "installed on request" do
allow(tab_from_keg).to receive(:installed_on_request).and_return(true) allow(tab_from_keg).to receive(:installed_on_request).and_return(true)
expect(described_class.send(:unused_formulae_with_no_formula_dependents, formulae)) expect(described_class.send(:unused_formulae_with_no_formula_dependents, formulae))
.to eq([]) .to eq([])
end end
specify "not installed on request" do specify "not installed on request" do
allow(tab_from_keg).to receive(:installed_on_request).and_return(false) allow(tab_from_keg).to receive(:installed_on_request).and_return(false)
expect(described_class.send(:unused_formulae_with_no_formula_dependents, formulae)) expect(described_class.send(:unused_formulae_with_no_formula_dependents, formulae))
.to match_array(formulae) .to match_array(formulae)
end end
end end

View File

@ -10,7 +10,8 @@ describe User do
describe "#gui?" do describe "#gui?" do
before do before do
allow(SystemCommand).to receive(:run).with("who", any_args) allow(SystemCommand).to receive(:run)
.with("who", any_args)
.and_return([who_output, "", instance_double(Process::Status, success?: true)]) .and_return([who_output, "", instance_double(Process::Status, success?: true)])
end end