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}/**/*"
- "os.rb"
# make rspec formatting more flexible
Layout/MultilineMethodCallIndentation:
Exclude:
- "**/*_spec.rb"
Naming/PredicateName:
AllowedMethods:
- is_32_bit?

View File

@ -232,10 +232,9 @@ describe Cask::Cask, :cask do
context "when loaded from json file" do
it "returns expected hash" do
expect(Homebrew::API::Cask).not_to receive(:fetch_source)
hash = Cask::CaskLoader::FromAPILoader
.new("everything", from_json: JSON.parse(expected_json))
.load(config: nil)
.to_h
hash = Cask::CaskLoader::FromAPILoader.new(
"everything", from_json: JSON.parse(expected_json)
).load(config: nil).to_h
expect(hash).to be_a(Hash)
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
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|
caffeine = f.call(*args)
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
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|
caffeine = f.call(*args)
expect(caffeine.config.appdir).to eq appdir
@ -57,7 +59,8 @@ describe Cask::Cmd::Install, :cask do
global_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|
caffeine = f.call(*args)
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
expect { described_class.run("local-caffeine") }
.to raise_error(Cask::CaskNotInstalledError, /is not installed/)
.to raise_error(Cask::CaskNotInstalledError, /is not installed/)
end
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
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

View File

@ -41,14 +41,16 @@ describe CompilerSelector do
it "returns gcc-6 if gcc formula offers gcc-6 on mac", :needs_macos do
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")))
expect(selector.compiler).to eq("gcc-6")
end
it "returns gcc-5 if gcc formula offers gcc-5 on linux", :needs_linux do
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")))
expect(selector.compiler).to eq("gcc-5")
end
@ -57,7 +59,8 @@ describe CompilerSelector do
software_spec.fails_with(:clang)
software_spec.fails_with(gcc: "5")
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")))
expect(selector.compiler).to eq("gcc-6")
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
software_spec.fails_with(:clang)
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")))
expect(selector.compiler).to eq("gcc-7")
end

View File

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

View File

@ -20,12 +20,13 @@ describe CurlGitHubPackagesDownloadStrategy do
end
it "calls curl with anonymous authentication headers" do
expect(strategy).to receive(:system_command).with(
/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))
expect(strategy).to receive(:system_command)
.with(
/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))
strategy.fetch
end
@ -34,12 +35,13 @@ describe CurlGitHubPackagesDownloadStrategy do
let(:authorization) { "Bearer dead-beef-cafe" }
it "calls curl with the provided header value" do
expect(strategy).to receive(:system_command).with(
/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))
expect(strategy).to receive(:system_command)
.with(
/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))
strategy.fetch
end

View File

@ -29,12 +29,13 @@ describe CurlPostDownloadStrategy do
}
it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with(
/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))
expect(strategy).to receive(:system_command)
.with(
/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))
strategy.fetch
end
@ -44,12 +45,13 @@ describe CurlPostDownloadStrategy do
let(:specs) { { using: :post } }
it "adds the appropriate curl args" do
expect(strategy).to receive(:system_command).with(
/curl/,
hash_including(args: array_including_cons("-X", "POST")),
)
.at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
expect(strategy).to receive(:system_command)
.with(
/curl/,
hash_including(args: array_including_cons("-X", "POST")),
)
.at_least(:once)
.and_return(instance_double(SystemCommand::Result, success?: true, stdout: "", assert_success!: nil))
strategy.fetch
end

View File

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

View File

@ -191,7 +191,8 @@ describe Resource do
fn = instance_double(Pathname, file?: true, basename: "foo")
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))
expect {

View File

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

View File

@ -10,7 +10,8 @@ describe User do
describe "#gui?" 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)])
end