diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index b5100bff15..19015c00d1 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -307,7 +307,7 @@ module Cask return end - command.run(executable_path, script_arguments) + command.run(executable_path, **script_arguments) sleep 1 end @@ -430,11 +430,11 @@ module Cask success end - def uninstall_rmdir(*args) + def uninstall_rmdir(*args, **kwargs) return if args.empty? ohai "Removing directories if empty:" - recursive_rmdir(*args) + recursive_rmdir(*args, **kwargs) end end end diff --git a/Library/Homebrew/cask/cmd/upgrade.rb b/Library/Homebrew/cask/cmd/upgrade.rb index ec97f1dccc..a96275cbe2 100644 --- a/Library/Homebrew/cask/cmd/upgrade.rb +++ b/Library/Homebrew/cask/cmd/upgrade.rb @@ -35,8 +35,9 @@ module Cask switch "--dry-run", description: "Show what would be upgraded, but do not actually upgrade anything." - OPTIONS.each do |option| - send(*option) + OPTIONS.map(&:dup).each do |option| + kwargs = option.pop + send(*option, **kwargs) end end end diff --git a/Library/Homebrew/cask/url.rb b/Library/Homebrew/cask/url.rb index fa09e3a0a5..6221f0414e 100644 --- a/Library/Homebrew/cask/url.rb +++ b/Library/Homebrew/cask/url.rb @@ -223,7 +223,7 @@ class URL < Delegator return @raw_interpolated_url if defined?(@raw_interpolated_url) @raw_interpolated_url = - Pathname(@caller_location.absolute_path) + Pathname(@caller_location.path) .each_line.drop(@caller_location.lineno - 1) .first&.then { |line| line[/url\s+"([^"]+)"/, 1] } end diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 3f2dc9de8c..64e8d4eb49 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -134,8 +134,8 @@ module Homebrew end end - def respond_to_missing?(*) - !frozen? + def respond_to_missing?(method_name, *) + !frozen? || @table.key?(method_name) end def method_missing(method_name, *args) diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 68e3f1e24f..94571c54d5 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -25,7 +25,7 @@ module Homebrew begin Homebrew.send(cmd_args_method_name) if require?(cmd_path) rescue NoMethodError => e - raise if e.name != cmd_args_method_name + raise if e.name.to_sym != cmd_args_method_name nil end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 030088e88e..b5c62e7562 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -182,7 +182,7 @@ module Homebrew end # Check style in a single batch run up front for performance - style_offenses = Style.check_style_json(style_files, style_options) if style_files + style_offenses = Style.check_style_json(style_files, **style_options) if style_files # load licenses spdx_license_data = SPDX.license_data spdx_exception_data = SPDX.exception_data diff --git a/Library/Homebrew/dev-cmd/style.rb b/Library/Homebrew/dev-cmd/style.rb index 4c4867ae68..d99973d591 100644 --- a/Library/Homebrew/dev-cmd/style.rb +++ b/Library/Homebrew/dev-cmd/style.rb @@ -72,6 +72,6 @@ module Homebrew options[:except_cops] = %w[FormulaAuditStrict] end - Homebrew.failed = !Style.check_style_and_print(target, options) + Homebrew.failed = !Style.check_style_and_print(target, **options) end end diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index 07a885288f..b0868a87fe 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -99,6 +99,7 @@ module Homebrew HOMEBREW_CACHE HOMEBREW_LOGS HOMEBREW_TEMP + HOMEBREW_USE_RUBY_FROM_PATH ] Homebrew::EnvConfig::ENVS.keys.map(&:to_s).each do |env| next if allowed_test_env.include?(env) diff --git a/Library/Homebrew/livecheck/strategy/sparkle.rb b/Library/Homebrew/livecheck/strategy/sparkle.rb index ae1e30567e..6b50d97510 100644 --- a/Library/Homebrew/livecheck/strategy/sparkle.rb +++ b/Library/Homebrew/livecheck/strategy/sparkle.rb @@ -174,7 +174,7 @@ module Homebrew if block block_return_value = case block.parameters[0] - when [:opt, :item], [:rest] + when [:opt, :item], [:rest], [:req] regex.present? ? yield(item, regex) : yield(item) when [:opt, :items] regex.present? ? yield(items, regex) : yield(items) diff --git a/Library/Homebrew/test/cask/dsl/appcast_spec.rb b/Library/Homebrew/test/cask/dsl/appcast_spec.rb index f6ba18aef4..3d4edef3cf 100644 --- a/Library/Homebrew/test/cask/dsl/appcast_spec.rb +++ b/Library/Homebrew/test/cask/dsl/appcast_spec.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true describe Cask::DSL::Appcast do - subject(:appcast) { described_class.new(url, params) } + subject(:appcast) { described_class.new(url, **params) } let(:url) { "https://brew.sh" } let(:uri) { URI(url) } diff --git a/Library/Homebrew/test/cask/pkg_spec.rb b/Library/Homebrew/test/cask/pkg_spec.rb index 2579525675..ad370d4055 100644 --- a/Library/Homebrew/test/cask/pkg_spec.rb +++ b/Library/Homebrew/test/cask/pkg_spec.rb @@ -28,11 +28,20 @@ describe Cask::Pkg, :cask do expect(file).not_to exist end + some_specials.each do |file| + expect(file).not_to exist + end + some_dirs.each do |dir| expect(dir).not_to exist end expect(root_dir).not_to exist + ensure + some_files&.each { |path| FileUtils.rm_rf(path) } + some_specials&.each { |path| FileUtils.rm_rf(path) } + some_dirs&.each { |path| FileUtils.rm_rf(path) } + FileUtils.rm_rf(root_dir) if root_dir end describe "pkgutil" do @@ -79,6 +88,9 @@ describe Cask::Pkg, :cask do expect(broken_symlink).not_to exist expect(fake_dir).to exist expect(fake_root).not_to exist + ensure + FileUtils.rm_rf(fake_dir) if fake_dir + FileUtils.rm_rf(fake_root) if fake_root end it "snags permissions on ornery dirs, but returns them afterwards" do @@ -109,8 +121,12 @@ describe Cask::Pkg, :cask do fake_dir.chmod(0777) expect(fake_file).to be_a_file - - FileUtils.rm_r fake_dir + ensure + if fake_dir + fake_dir.chmod(0777) + FileUtils.rm_rf(fake_dir) + end + FileUtils.rm_rf(fake_root) if fake_root end end diff --git a/Library/Homebrew/test/resource_spec.rb b/Library/Homebrew/test/resource_spec.rb index da3206393a..908a88f452 100644 --- a/Library/Homebrew/test/resource_spec.rb +++ b/Library/Homebrew/test/resource_spec.rb @@ -58,7 +58,7 @@ describe Resource do it "does not mutate the specifications hash" do specs = { using: :git, branch: "master" } - resource.url("foo", specs) + resource.url("foo", **specs) expect(resource.specs).to eq(branch: "master") expect(resource.using).to eq(:git) expect(specs).to eq(using: :git, branch: "master") diff --git a/Library/Homebrew/test/rubocop_spec.rb b/Library/Homebrew/test/rubocop_spec.rb index 795d91a14a..707d936e0d 100644 --- a/Library/Homebrew/test/rubocop_spec.rb +++ b/Library/Homebrew/test/rubocop_spec.rb @@ -7,7 +7,7 @@ describe "RuboCop" do context "when calling `rubocop` outside of the Homebrew environment" do before do ENV.each_key do |key| - ENV.delete(key) if key.start_with?("HOMEBREW_") + ENV.delete(key) if key.start_with?("HOMEBREW_") && key != "HOMEBREW_USE_RUBY_FROM_PATH" end ENV["XDG_CACHE_HOME"] = (HOMEBREW_CACHE.realpath/"style").to_s diff --git a/Library/Homebrew/test/settings_spec.rb b/Library/Homebrew/test/settings_spec.rb index 8df4063fc2..2b29d2f9b6 100644 --- a/Library/Homebrew/test/settings_spec.rb +++ b/Library/Homebrew/test/settings_spec.rb @@ -51,7 +51,7 @@ describe Homebrew::Settings do end it "returns if the repo doesn't have a configuration file" do - expect { described_class.write("foo", repo: HOMEBREW_REPOSITORY/"bar") }.not_to raise_error + expect { described_class.write("foo", false, repo: HOMEBREW_REPOSITORY/"bar") }.not_to raise_error end end diff --git a/Library/Homebrew/test/support/helper/cask/never_sudo_system_command.rb b/Library/Homebrew/test/support/helper/cask/never_sudo_system_command.rb index b5859c174e..8cb5e22562 100644 --- a/Library/Homebrew/test/support/helper/cask/never_sudo_system_command.rb +++ b/Library/Homebrew/test/support/helper/cask/never_sudo_system_command.rb @@ -4,7 +4,7 @@ require "system_command" class NeverSudoSystemCommand < SystemCommand - def self.run(command, options = {}) - super(command, options.merge(sudo: false)) + def self.run(command, **options) + super(command, **options.merge(sudo: false)) end end diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index 3a3f7b2ce0..6b5e5c219f 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -124,7 +124,7 @@ describe SystemCommand do shared_examples "it returns '1 2 3 4 5 6'" do describe "its result" do - subject { described_class.run(command, options) } + subject { described_class.run(command, **options) } it { is_expected.to be_a_success } its(:stdout) { is_expected.to eq([1, 3, 5, nil].join("\n")) } @@ -136,7 +136,7 @@ describe SystemCommand do it "echoes only STDERR" do expected = [2, 4, 6].map { |i| "#{i}\n" }.join expect { - described_class.run(command, options) + described_class.run(command, **options) }.to output(expected).to_stderr end @@ -149,7 +149,7 @@ describe SystemCommand do end it "echoes both STDOUT and STDERR" do - expect { described_class.run(command, options) } + expect { described_class.run(command, **options) } .to output("1\n3\n5\n").to_stdout .and output("2\n4\n6\n").to_stderr end @@ -164,7 +164,7 @@ describe SystemCommand do it "echoes nothing" do expect { - described_class.run(command, options) + described_class.run(command, **options) }.to output("").to_stdout end @@ -179,7 +179,7 @@ describe SystemCommand do it "echoes only STDOUT" do expected = [1, 3, 5].map { |i| "#{i}\n" }.join expect { - described_class.run(command, options) + described_class.run(command, **options) }.to output(expected).to_stdout end @@ -198,7 +198,7 @@ describe SystemCommand do it "returns without deadlocking" do wait(30).for { - described_class.run(command, options) + described_class.run(command, **options) }.to be_a_success end end diff --git a/Library/Homebrew/test/utils/ruby_check_version_script_spec.rb b/Library/Homebrew/test/utils/ruby_check_version_script_spec.rb index cb3bb59b5b..543a421d64 100644 --- a/Library/Homebrew/test/utils/ruby_check_version_script_spec.rb +++ b/Library/Homebrew/test/utils/ruby_check_version_script_spec.rb @@ -4,7 +4,11 @@ describe Utils do describe "ruby_check_version_script" do subject do - quiet_system "#{HOMEBREW_LIBRARY_PATH}/utils/ruby_check_version_script.rb", required_ruby_version + homebrew_env = ENV.select { |key, _| key.start_with?("HOMEBREW_") } + Bundler.with_unbundled_env do + ENV.update(homebrew_env) + quiet_system "#{HOMEBREW_LIBRARY_PATH}/utils/ruby_check_version_script.rb", required_ruby_version + end end before do @@ -12,8 +16,8 @@ describe Utils do ENV.delete("HOMEBREW_USE_RUBY_FROM_PATH") end - describe "succeeds on Homebrew required Ruby version" do - let(:required_ruby_version) { HOMEBREW_REQUIRED_RUBY_VERSION } + describe "succeeds on the running Ruby version" do + let(:required_ruby_version) { RUBY_VERSION } it { is_expected.to be true } end diff --git a/Library/Homebrew/test/utils/spdx_spec.rb b/Library/Homebrew/test/utils/spdx_spec.rb index 192098b32d..d02de416ef 100644 --- a/Library/Homebrew/test/utils/spdx_spec.rb +++ b/Library/Homebrew/test/utils/spdx_spec.rb @@ -181,15 +181,15 @@ describe SPDX do end it "returns multiple licenses with :any" do - expect(described_class.license_expression_to_string(any_of: ["MIT", "0BSD"])).to eq "MIT or 0BSD" + expect(described_class.license_expression_to_string({ any_of: ["MIT", "0BSD"] })).to eq "MIT or 0BSD" end it "returns multiple licenses with :all" do - expect(described_class.license_expression_to_string(all_of: ["MIT", "0BSD"])).to eq "MIT and 0BSD" + expect(described_class.license_expression_to_string({ all_of: ["MIT", "0BSD"] })).to eq "MIT and 0BSD" end it "returns multiple licenses with plus" do - expect(described_class.license_expression_to_string(any_of: ["MIT", "EPL-1.0+"])).to eq "MIT or EPL-1.0+" + expect(described_class.license_expression_to_string({ any_of: ["MIT", "EPL-1.0+"] })).to eq "MIT or EPL-1.0+" end it "returns license and exception" do diff --git a/Library/Homebrew/test/utils/user_spec.rb b/Library/Homebrew/test/utils/user_spec.rb index 610d6b4c8b..006998a652 100644 --- a/Library/Homebrew/test/utils/user_spec.rb +++ b/Library/Homebrew/test/utils/user_spec.rb @@ -10,7 +10,7 @@ describe User do describe "#gui?" do before do - allow(SystemCommand).to receive(:run).with("who", {}) + allow(SystemCommand).to receive(:run).with("who", any_args) .and_return([who_output, "", instance_double(Process::Status, success?: true)]) end diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index bd2634557f..8fe6ca9772 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -412,7 +412,7 @@ module Utils # Unknown charset in Content-Type header end end - file_contents = File.read(file.path, open_args) + file_contents = File.read(file.path, **open_args) file_hash = Digest::SHA2.hexdigest(file_contents) if hash_needed end