Apply corrections from brew style --fix

This commit is contained in:
Carlo Cabrera 2025-07-12 02:06:37 +08:00 committed by Carlo Cabrera
parent cb15b67b8e
commit 4a608bfb11
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
65 changed files with 155 additions and 157 deletions

View File

@ -37,12 +37,12 @@ module Homebrew
if casks.any? if casks.any?
args = zap ? ["--zap"] : [] args = zap ? ["--zap"] : []
Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--cask", *args, "--force", *casks Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--cask", *args, "--force", *casks
puts "Uninstalled #{casks.size} cask#{(casks.size == 1) ? "" : "s"}" puts "Uninstalled #{casks.size} cask#{"s" if casks.size != 1}"
end end
if formulae.any? if formulae.any?
Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--formula", "--force", *formulae Kernel.system HOMEBREW_BREW_FILE, "uninstall", "--formula", "--force", *formulae
puts "Uninstalled #{formulae.size} formula#{(formulae.size == 1) ? "" : "e"}" puts "Uninstalled #{formulae.size} formula#{"e" if formulae.size != 1}"
end end
Kernel.system HOMEBREW_BREW_FILE, "untap", *taps if taps.any? Kernel.system HOMEBREW_BREW_FILE, "untap", *taps if taps.any?

View File

@ -194,7 +194,7 @@ class Caveats
startup = formula.service.requires_root? startup = formula.service.requires_root?
if Utils::Service.running?(formula) if Utils::Service.running?(formula)
s << "To restart #{formula.full_name} after an upgrade:" s << "To restart #{formula.full_name} after an upgrade:"
s << " #{startup ? "sudo " : ""}brew services restart #{formula.full_name}" s << " #{"sudo " if startup}brew services restart #{formula.full_name}"
elsif startup elsif startup
s << "To start #{formula.full_name} now and restart at startup:" s << "To start #{formula.full_name} now and restart at startup:"
s << " sudo brew services start #{formula.full_name}" s << " sudo brew services start #{formula.full_name}"

View File

@ -589,7 +589,7 @@ module Homebrew
#{leading_spaces}resource "#{resource.name}" do #{leading_spaces}resource "#{resource.name}" do
#{leading_spaces} url "#{new_url}"#{new_mirrors.map { |m| "\n#{leading_spaces} mirror \"#{m}\"" }.join} #{leading_spaces} url "#{new_url}"#{new_mirrors.map { |m| "\n#{leading_spaces} mirror \"#{m}\"" }.join}
#{leading_spaces} sha256 "#{new_hash}" #{leading_spaces} sha256 "#{new_hash}"
#{forced_version ? "#{leading_spaces} version \"#{version}\"\n" : ""} #{"#{leading_spaces} version \"#{version}\"\n" if forced_version}
#{leading_spaces} livecheck do #{leading_spaces} livecheck do
#{leading_spaces} formula :parent #{leading_spaces} formula :parent
#{leading_spaces} end #{leading_spaces} end

View File

@ -20,7 +20,6 @@ module Homebrew
def enqueue(downloadable, force: false) def enqueue(downloadable, force: false)
quiet = pool.max_length > 1 quiet = pool.max_length > 1
# Passing in arguments from outside into the future is a common `concurrent-ruby` pattern. # Passing in arguments from outside into the future is a common `concurrent-ruby` pattern.
# rubocop:disable Lint/ShadowingOuterLocalVariable
Concurrent::Promises.future_on(pool, downloadable, force, quiet) do |downloadable, force, quiet| Concurrent::Promises.future_on(pool, downloadable, force, quiet) do |downloadable, force, quiet|
downloadable.clear_cache if force downloadable.clear_cache if force
downloadable.fetch(quiet:) downloadable.fetch(quiet:)

View File

@ -20,11 +20,11 @@ class File
# file.write('hello') # file.write('hello')
# end # end
sig { sig {
type_parameters(:out).params( type_parameters(:Out).params(
file_name: T.any(Pathname, String), file_name: T.any(Pathname, String),
temp_dir: String, temp_dir: String,
_block: T.proc.params(arg0: Tempfile).returns(T.type_parameter(:out)), _block: T.proc.params(arg0: Tempfile).returns(T.type_parameter(:Out)),
).returns(T.type_parameter(:out)) ).returns(T.type_parameter(:Out))
} }
def self.atomic_write(file_name, temp_dir = dirname(file_name), &_block) def self.atomic_write(file_name, temp_dir = dirname(file_name), &_block)
require "tempfile" unless defined?(Tempfile) require "tempfile" unless defined?(Tempfile)

View File

@ -3,18 +3,18 @@
class Hash class Hash
sig { sig {
type_parameters(:k2).params( type_parameters(:K2).params(
other_hash: T::Hash[T.type_parameter(:k2), T.untyped], other_hash: T::Hash[T.type_parameter(:K2), T.untyped],
block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)), block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)),
).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:K2)), T.untyped])
} }
def deep_merge(other_hash, &block); end def deep_merge(other_hash, &block); end
sig { sig {
type_parameters(:k2).params( type_parameters(:K2).params(
other_hash: T::Hash[T.type_parameter(:k2), T.untyped], other_hash: T::Hash[T.type_parameter(:K2), T.untyped],
block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)), block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)),
).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:K2)), T.untyped])
} }
def deep_merge!(other_hash, &block); end def deep_merge!(other_hash, &block); end
end end

View File

@ -2,16 +2,16 @@
class Hash class Hash
sig { sig {
type_parameters(:out).params( type_parameters(:Out).params(
block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)), block: T.proc.params(o: Hash::V).returns(T.type_parameter(:Out)),
).returns(T::Hash[Hash::K, T.type_parameter(:out)]) ).returns(T::Hash[Hash::K, T.type_parameter(:Out)])
} }
def deep_transform_values(&block); end def deep_transform_values(&block); end
sig { sig {
type_parameters(:out).params( type_parameters(:Out).params(
block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)), block: T.proc.params(o: Hash::V).returns(T.type_parameter(:Out)),
).returns(T::Hash[Hash::K, T.type_parameter(:out)]) ).returns(T::Hash[Hash::K, T.type_parameter(:Out)])
} }
def deep_transform_values!(&block); end def deep_transform_values!(&block); end
end end

View File

@ -3,16 +3,16 @@
class Hash class Hash
sig { sig {
type_parameters(:out).params( type_parameters(:Out).params(
block: T.proc.params(o: K).returns(T.type_parameter(:out)), block: T.proc.params(o: K).returns(T.type_parameter(:Out)),
).returns(T::Hash[T.type_parameter(:out), V]) ).returns(T::Hash[T.type_parameter(:Out), V])
} }
def deep_transform_keys(&block); end def deep_transform_keys(&block); end
sig { sig {
type_parameters(:out).params( type_parameters(:Out).params(
block: T.proc.params(o: K).returns(T.type_parameter(:out)), block: T.proc.params(o: K).returns(T.type_parameter(:Out)),
).returns(T::Hash[T.type_parameter(:out), V]) ).returns(T::Hash[T.type_parameter(:Out), V])
} }
def deep_transform_keys!(&block); end def deep_transform_keys!(&block); end

View File

@ -80,7 +80,7 @@ module Formulary
module PathnameWriteMkpath module PathnameWriteMkpath
refine Pathname do refine Pathname do
def write(content, offset = nil, **open_args) define_method(:write) do |_content, offset = nil, **open_args|
T.bind(self, Pathname) T.bind(self, Pathname)
raise "Will not overwrite #{self}" if exist? && !offset && !open_args[:mode]&.match?(/^a\+?$/) raise "Will not overwrite #{self}" if exist? && !offset && !open_args[:mode]&.match?(/^a\+?$/)
@ -133,7 +133,7 @@ module Formulary
rescue NameError => e rescue NameError => e
class_list = mod.constants class_list = mod.constants
.map { |const_name| mod.const_get(const_name) } .map { |const_name| mod.const_get(const_name) }
.select { |const| const.is_a?(Class) } .grep(Class)
new_exception = FormulaClassUnavailableError.new(name, path, class_name, class_list) new_exception = FormulaClassUnavailableError.new(name, path, class_name, class_list)
remove_const(namespace) remove_const(namespace)
raise new_exception, "", e.backtrace raise new_exception, "", e.backtrace
@ -354,13 +354,13 @@ module Formulary
link_overwrite overwrite_path link_overwrite overwrite_path
end end
def install define_method(:install) do
raise "Cannot build from source from abstract formula." raise "Cannot build from source from abstract formula."
end end
@post_install_defined_boolean = json_formula["post_install_defined"] @post_install_defined_boolean = json_formula["post_install_defined"]
@post_install_defined_boolean = true if @post_install_defined_boolean.nil? # Backwards compatibility @post_install_defined_boolean = true if @post_install_defined_boolean.nil? # Backwards compatibility
def post_install_defined? define_method(:post_install_defined?) do
self.class.instance_variable_get(:@post_install_defined_boolean) self.class.instance_variable_get(:@post_install_defined_boolean)
end end
@ -389,7 +389,7 @@ module Formulary
end end
@caveats_string = json_formula["caveats"] @caveats_string = json_formula["caveats"]
def caveats define_method(:caveats) do
caveats_string = self.class.instance_variable_get(:@caveats_string) caveats_string = self.class.instance_variable_get(:@caveats_string)
return unless caveats_string return unless caveats_string
@ -400,33 +400,33 @@ module Formulary
@tap_git_head_string = json_formula["tap_git_head"] @tap_git_head_string = json_formula["tap_git_head"]
def tap_git_head define_method(:tap_git_head) do
self.class.instance_variable_get(:@tap_git_head_string) self.class.instance_variable_get(:@tap_git_head_string)
end end
@oldnames_array = json_formula["oldnames"] || [json_formula["oldname"]].compact @oldnames_array = json_formula["oldnames"] || [json_formula["oldname"]].compact
def oldnames define_method(:oldnames) do
self.class.instance_variable_get(:@oldnames_array) self.class.instance_variable_get(:@oldnames_array)
end end
@aliases_array = json_formula.fetch("aliases", []) @aliases_array = json_formula.fetch("aliases", [])
def aliases define_method(:aliases) do
self.class.instance_variable_get(:@aliases_array) self.class.instance_variable_get(:@aliases_array)
end end
@versioned_formulae_array = json_formula.fetch("versioned_formulae", []) @versioned_formulae_array = json_formula.fetch("versioned_formulae", [])
def versioned_formulae_names define_method(:versioned_formulae_names) do
self.class.instance_variable_get(:@versioned_formulae_array) self.class.instance_variable_get(:@versioned_formulae_array)
end end
@ruby_source_path_string = json_formula["ruby_source_path"] @ruby_source_path_string = json_formula["ruby_source_path"]
def ruby_source_path define_method(:ruby_source_path) do
self.class.instance_variable_get(:@ruby_source_path_string) self.class.instance_variable_get(:@ruby_source_path_string)
end end
@ruby_source_checksum_string = json_formula.dig("ruby_source_checksum", "sha256") @ruby_source_checksum_string = json_formula.dig("ruby_source_checksum", "sha256")
@ruby_source_checksum_string ||= json_formula["ruby_source_sha256"] @ruby_source_checksum_string ||= json_formula["ruby_source_sha256"]
def ruby_source_checksum define_method(:ruby_source_checksum) do
checksum = self.class.instance_variable_get(:@ruby_source_checksum_string) checksum = self.class.instance_variable_get(:@ruby_source_checksum_string)
Checksum.new(checksum) if checksum Checksum.new(checksum) if checksum
end end

View File

@ -22,7 +22,7 @@ module Ignorable
Object.class_eval do Object.class_eval do
alias_method :original_raise, :raise alias_method :original_raise, :raise
def raise(*) define_method(:raise) do |*|
callcc do |continuation| callcc do |continuation|
super super
# Handle all possible exceptions. # Handle all possible exceptions.

View File

@ -465,9 +465,7 @@ module Homebrew
def collect_dependencies(formulae_installer, dependants) def collect_dependencies(formulae_installer, dependants)
formulae_dependencies = formulae_installer.flat_map do |f| formulae_dependencies = formulae_installer.flat_map do |f|
[f.formula, f.compute_dependencies.flatten.filter do |c| [f.formula, f.compute_dependencies.flatten.grep(Dependency).flat_map(&:to_formula)]
c.is_a? Dependency
end.flat_map(&:to_formula)]
end.flatten.uniq end.flatten.uniq
formulae_dependencies.concat(dependants.upgradeable) if dependants&.upgradeable formulae_dependencies.concat(dependants.upgradeable) if dependants&.upgradeable
formulae_dependencies.uniq formulae_dependencies.uniq

View File

@ -11,7 +11,8 @@ RSpec.describe Homebrew::AbstractCommand do
switch "--foo" switch "--foo"
flag "--bar=" flag "--bar="
end end
def run; end define_method(:run) do
end
end end
stub_const("TestCat", test_cat) stub_const("TestCat", test_cat)
end end
@ -47,8 +48,10 @@ RSpec.describe Homebrew::AbstractCommand do
describe "when command name is overridden" do describe "when command name is overridden" do
before do before do
tac = Class.new(described_class) do tac = Class.new(described_class) do
def self.command_name = "t-a-c" self.define_singleton_method(:command_name) do
def run; end "t-a-c"
define_method(:run) do
end
end end
stub_const("Tac", tac) stub_const("Tac", tac)
end end

View File

@ -9,7 +9,7 @@ RSpec.describe Homebrew::API::Cask do
stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir)
end end
def mock_curl_download(stdout:) define_method(:mock_curl_download) do |stdout:|
allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs|
kwargs[:to].write stdout kwargs[:to].write stdout
end end

View File

@ -9,7 +9,7 @@ RSpec.describe Homebrew::API::Formula do
stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir) stub_const("Homebrew::API::HOMEBREW_CACHE_API", cache_dir)
end end
def mock_curl_download(stdout:) define_method(:mock_curl_download) do |stdout:|
allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs|
kwargs[:to].write stdout kwargs[:to].write stdout
end end

View File

@ -8,12 +8,12 @@ RSpec.describe Homebrew::API do
let(:json_hash) { JSON.parse(json) } let(:json_hash) { JSON.parse(json) }
let(:json_invalid) { '{"foo":"bar"' } let(:json_invalid) { '{"foo":"bar"' }
def mock_curl_output(stdout: "", success: true) define_method(:mock_curl_output) do |stdout: "", success: true|
curl_output = instance_double(SystemCommand::Result, stdout:, success?: success) curl_output = instance_double(SystemCommand::Result, stdout:, success?: success)
allow(Utils::Curl).to receive(:curl_output).and_return curl_output allow(Utils::Curl).to receive(:curl_output).and_return curl_output
end end
def mock_curl_download(stdout:) define_method(:mock_curl_download) do |stdout:|
allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs| allow(Utils::Curl).to receive(:curl_download) do |*_args, **kwargs|
kwargs[:to].write stdout kwargs[:to].write stdout
end end

View File

@ -286,7 +286,7 @@ RSpec.describe Homebrew::Bundle::Commands::Cleanup do
vscode_extensions_to_uninstall: []) vscode_extensions_to_uninstall: [])
end end
def sane? define_method(:sane?) do
expect(described_class).to receive(:system_output_no_stderr).and_return("cleaned") expect(described_class).to receive(:system_output_no_stderr).and_return("cleaned")
end end

View File

@ -4,7 +4,7 @@ require "bundle"
require "bundle/dsl" require "bundle/dsl"
RSpec.describe Homebrew::Bundle::Dsl do RSpec.describe Homebrew::Bundle::Dsl do
def dsl_from_string(string) define_method(:dsl_from_string) do |string|
described_class.new(StringIO.new(string)) described_class.new(StringIO.new(string))
end end

View File

@ -3,7 +3,7 @@
require "cask/audit" require "cask/audit"
RSpec.describe Cask::Audit, :cask do RSpec.describe Cask::Audit, :cask do
def include_msg?(problems, msg) define_method(:include_msg?) do |problems, msg|
if msg.is_a?(Regexp) if msg.is_a?(Regexp)
Array(problems).any? { |problem| msg.match?(problem[:message]) } Array(problems).any? { |problem| msg.match?(problem[:message]) }
else else
@ -11,11 +11,11 @@ RSpec.describe Cask::Audit, :cask do
end end
end end
def passed?(audit) define_method(:passed?) do |audit|
!audit.errors? !audit.errors?
end end
def outcome(audit) define_method(:outcome) do |audit|
if passed?(audit) if passed?(audit)
"passed" "passed"
else else
@ -150,7 +150,7 @@ RSpec.describe Cask::Audit, :cask do
describe "#run!" do describe "#run!" do
subject(:run) { audit.run! } subject(:run) { audit.run! }
def tmp_cask(name, text) define_method(:tmp_cask) do |name, text|
path = Pathname.new "#{dir}/#{name}.rb" path = Pathname.new "#{dir}/#{name}.rb"
path.open("w") do |f| path.open("w") do |f|
f.write text f.write text

View File

@ -305,7 +305,7 @@ RSpec.describe Cask::DSL, :cask, :no_api do
expect(cask.caveats).to be_empty expect(cask.caveats).to be_empty
cask = Cask::Cask.new("cask-with-caveats") do cask = Cask::Cask.new("cask-with-caveats") do
def caveats define_method(:caveats) do
<<~EOS <<~EOS
When you install this Cask, you probably want to know this. When you install this Cask, you probably want to know this.
EOS EOS

View File

@ -21,7 +21,7 @@ RSpec.describe Caveats do
f = formula do f = formula do
url "foo-1.0" url "foo-1.0"
def caveats define_method(:caveats) do
"something" "something"
end end
end end
@ -214,7 +214,7 @@ RSpec.describe Caveats do
url "foo-1.0" url "foo-1.0"
keg_only "some reason" keg_only "some reason"
def caveats define_method(:caveats) do
"something else" "something else"
end end

View File

@ -3,7 +3,7 @@
require "formula" require "formula"
RSpec.describe Formula do RSpec.describe Formula do
def formula(&block) define_method(:formula) do |&block|
super do super do
url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz"
instance_eval(&block) instance_eval(&block)

View File

@ -204,7 +204,7 @@ RSpec.describe Cleaner do
end end
describe "::skip_clean" do describe "::skip_clean" do
def stub_formula_skip_clean(skip_paths) define_method(:stub_formula_skip_clean) do |skip_paths|
formula("cleaner_test") do formula("cleaner_test") do
url "foo-1.0" url "foo-1.0"

View File

@ -3,12 +3,12 @@
require "cli/named_args" require "cli/named_args"
RSpec.describe Homebrew::CLI::NamedArgs do RSpec.describe Homebrew::CLI::NamedArgs do
def setup_unredable_formula(name) define_method(:setup_unredable_formula) do |name|
error = FormulaUnreadableError.new(name, RuntimeError.new("testing")) error = FormulaUnreadableError.new(name, RuntimeError.new("testing"))
allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error) allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error)
end end
def setup_unredable_cask(name) define_method(:setup_unredable_cask) do |name|
error = Cask::CaskUnreadableError.new(name, "testing") error = Cask::CaskUnreadableError.new(name, "testing")
allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error) allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error)

View File

@ -5,8 +5,7 @@ require "cmd/shared_examples/args_parse"
require "tab" require "tab"
RSpec.describe Homebrew::Cmd::TabCmd do RSpec.describe Homebrew::Cmd::TabCmd do
def installed_on_request?(formula) define_method(:installed_on_request?) do |formula|
# `brew` subprocesses can change the tab, invalidating the cached values.
Tab.clear_cache Tab.clear_cache
Tab.for_formula(formula).installed_on_request Tab.for_formula(formula).installed_on_request
end end

View File

@ -19,7 +19,7 @@ RSpec.describe Homebrew::Cmd::Untap do
describe "#installed_formulae_for", :integration_test do describe "#installed_formulae_for", :integration_test do
shared_examples "finds installed formulae in tap", :no_api do shared_examples "finds installed formulae in tap", :no_api do
def load_formula(name:, with_formula_file: false, mock_install: false) define_method(:load_formula) do |name:, with_formula_file: false, mock_install: false|
formula = if with_formula_file formula = if with_formula_file
path = setup_test_formula(name, tap:) path = setup_test_formula(name, tap:)
Formulary.factory(path) Formulary.factory(path)
@ -85,7 +85,7 @@ RSpec.describe Homebrew::Cmd::Untap do
describe "#installed_casks_for", :cask do describe "#installed_casks_for", :cask do
shared_examples "finds installed casks in tap", :no_api do shared_examples "finds installed casks in tap", :no_api do
def load_cask(token:, with_cask_file: false, mock_install: false) define_method(:load_cask) do |token:, with_cask_file: false, mock_install: false|
cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:) cask_loader = Cask::CaskLoader::FromContentLoader.new(<<~RUBY, tap:)
cask '#{token}' do cask '#{token}' do
version "1.2.3" version "1.2.3"

View File

@ -12,7 +12,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do
let(:tap) { CoreTap.instance } let(:tap) { CoreTap.instance }
let(:reporter_class) do let(:reporter_class) do
Class.new(described_class) do Class.new(described_class) do
def initialize(tap) define_method(:initialize) do |tap|
@tap = tap @tap = tap
ENV["HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"] = "12345678" ENV["HOMEBREW_UPDATE_BEFORE#{tap.repository_var_suffix}"] = "12345678"
@ -25,7 +25,7 @@ RSpec.describe Homebrew::Cmd::UpdateReport do
let(:reporter) { reporter_class.new(tap) } let(:reporter) { reporter_class.new(tap) }
let(:hub) { ReporterHub.new } let(:hub) { ReporterHub.new }
def perform_update(fixture_name = "") define_method(:perform_update) do |fixture_name = ""|
allow(Formulary).to receive(:factory).and_return(instance_double(Formula, pkg_version: "1.0")) allow(Formulary).to receive(:factory).and_return(instance_double(Formula, pkg_version: "1.0"))
allow(FormulaVersions).to receive(:new).and_return(instance_double(FormulaVersions, formula_at_revision: "2.0")) allow(FormulaVersions).to receive(:new).and_return(instance_double(FormulaVersions, formula_at_revision: "2.0"))

View File

@ -25,7 +25,7 @@ RSpec.describe Homebrew::Completions do
end end
context "when linking or unlinking completions" do context "when linking or unlinking completions" do
def setup_completions(external:) define_method(:setup_completions) do |external:|
internal_bash_completion = internal_path/"completions/bash" internal_bash_completion = internal_path/"completions/bash"
external_bash_completion = external_path/"completions/bash" external_bash_completion = external_path/"completions/bash"
@ -39,19 +39,19 @@ RSpec.describe Homebrew::Completions do
end end
end end
def setup_completions_setting(state, setting: "linkcompletions") define_method(:setup_completions_setting) do |state, setting: "linkcompletions"|
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
system "git", "config", "--replace-all", "homebrew.#{setting}", state.to_s system "git", "config", "--replace-all", "homebrew.#{setting}", state.to_s
end end
end end
def read_completions_setting(setting: "linkcompletions") define_method(:read_completions_setting) do |setting: "linkcompletions"|
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
Utils.popen_read("git", "config", "--get", "homebrew.#{setting}").chomp.presence Utils.popen_read("git", "config", "--get", "homebrew.#{setting}").chomp.presence
end end
end end
def delete_completions_setting(setting: "linkcompletions") define_method(:delete_completions_setting) do |setting: "linkcompletions"|
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
system "git", "config", "--unset-all", "homebrew.#{setting}" system "git", "config", "--unset-all", "homebrew.#{setting}"
end end

View File

@ -8,7 +8,7 @@ RSpec.describe Dependable do
subject(:dependable) do subject(:dependable) do
Class.new do Class.new do
include Dependable include Dependable
def initialize define_method(:initialize) do
@tags = ["foo", "bar", :build] @tags = ["foo", "bar", :build]
end end
end.new end.new

View File

@ -7,11 +7,11 @@ RSpec.describe DependencyCollector do
subject(:collector) { described_class.new } subject(:collector) { described_class.new }
def find_dependency(name) define_method(:find_dependency) do |name|
collector.deps.find { |dep| dep.name == name } collector.deps.find { |dep| dep.name == name }
end end
def find_requirement(klass) define_method(:find_requirement) do |klass|
collector.requirements.find { |req| req.is_a? klass } collector.requirements.find { |req| req.is_a? klass }
end end

View File

@ -3,7 +3,7 @@
require "dependency" require "dependency"
RSpec.describe Dependency do RSpec.describe Dependency do
def build_dep(name, tags = [], deps = []) define_method(:build_dep) do |name, tags = [], deps = []|
dep = described_class.new(name.to_s, tags) dep = described_class.new(name.to_s, tags)
allow(dep).to receive(:to_formula).and_return \ allow(dep).to receive(:to_formula).and_return \
instance_double(Formula, deps:, name:, full_name: name) instance_double(Formula, deps:, name:, full_name: name)

View File

@ -4,7 +4,7 @@ require "cmd/shared_examples/args_parse"
require "dev-cmd/bottle" require "dev-cmd/bottle"
RSpec.describe Homebrew::DevCmd::Bottle do RSpec.describe Homebrew::DevCmd::Bottle do
def stub_hash(parameters) define_method(:stub_hash) do |parameters|
<<~EOS <<~EOS
{ {
"#{parameters[:name]}":{ "#{parameters[:name]}":{

View File

@ -4,7 +4,7 @@ require "dev-cmd/determine-test-runners"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe Homebrew::DevCmd::DetermineTestRunners do RSpec.describe Homebrew::DevCmd::DetermineTestRunners do
def get_runners(file) define_method(:get_runners) do |file|
runner_line = File.open(file).first runner_line = File.open(file).first
json_text = runner_line[/runners=(.*)/, 1] json_text = runner_line[/runners=(.*)/, 1]
runner_hash = JSON.parse(json_text) runner_hash = JSON.parse(json_text)

View File

@ -15,7 +15,7 @@ RSpec.describe GitDownloadStrategy do
FileUtils.mkpath cached_location FileUtils.mkpath cached_location
end end
def git_commit_all define_method(:git_commit_all) do
system "git", "add", "--all" system "git", "add", "--all"
# Allow instance variables here to have nice commit messages. # Allow instance variables here to have nice commit messages.
# rubocop:disable RSpec/InstanceVariable # rubocop:disable RSpec/InstanceVariable
@ -24,7 +24,7 @@ RSpec.describe GitDownloadStrategy do
# rubocop:enable RSpec/InstanceVariable # rubocop:enable RSpec/InstanceVariable
end end
def setup_git_repo define_method(:setup_git_repo) do
system "git", "-c", "init.defaultBranch=master", "init" system "git", "-c", "init.defaultBranch=master", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
FileUtils.touch "README" FileUtils.touch "README"

View File

@ -5,14 +5,14 @@ require "extend/blank"
RSpec.describe Object do RSpec.describe Object do
let(:empty_true) do let(:empty_true) do
Class.new(described_class) do Class.new(described_class) do
def empty? define_method(:empty?) do
0 0
end end
end end
end end
let(:empty_false) do let(:empty_false) do
Class.new(described_class) do Class.new(described_class) do
def empty? define_method(:empty?) do
false false
end end
end end

View File

@ -3,7 +3,7 @@
RSpec.describe Kernel do RSpec.describe Kernel do
let(:dir) { mktmpdir } let(:dir) { mktmpdir }
def esc(code) define_method(:esc) do |code|
/(\e\[\d+m)*\e\[#{code}m/ /(\e\[\d+m)*\e\[#{code}m/
end end

View File

@ -16,7 +16,7 @@ RSpec.describe Homebrew::FormulaAuditor do
let(:tap_path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-bar" } let(:tap_path) { HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-bar" }
let(:formula_path) { tap_path/formula_subpath } let(:formula_path) { tap_path/formula_subpath }
def formula_auditor(name, text, options = {}) define_method(:formula_auditor) do |name, text, options = {}|
path = Pathname.new "#{dir}/#{name}.rb" path = Pathname.new "#{dir}/#{name}.rb"
path.open("w") do |f| path.open("w") do |f|
f.write text f.write text
@ -34,14 +34,14 @@ RSpec.describe Homebrew::FormulaAuditor do
described_class.new(formula, options) described_class.new(formula, options)
end end
def formula_gsub(before, after = "") define_method(:formula_gsub) do |before, after = ""|
text = formula_path.read text = formula_path.read
text.gsub! before, after text.gsub! before, after
formula_path.unlink formula_path.unlink
formula_path.write text formula_path.write text
end end
def formula_gsub_origin_commit(before, after = "") define_method(:formula_gsub_origin_commit) do |before, after = ""|
text = origin_formula_path.read text = origin_formula_path.read
text.gsub!(before, after) text.gsub!(before, after)
origin_formula_path.unlink origin_formula_path.unlink

View File

@ -16,7 +16,7 @@ RSpec.describe FormulaInstaller do
match(&:poured_from_bottle) match(&:poured_from_bottle)
end end
def temporarily_install_bottle(formula) define_method(:temporarily_install_bottle) do |formula|
expect(formula).not_to be_latest_version_installed expect(formula).not_to be_latest_version_installed
expect(formula).to be_bottled expect(formula).to be_bottled
expect(formula).to pour_bottle expect(formula).to pour_bottle
@ -25,7 +25,7 @@ RSpec.describe FormulaInstaller do
stub_formula_loader formula("glibc") { url "glibc-1.0" } stub_formula_loader formula("glibc") { url "glibc-1.0" }
stub_formula_loader formula stub_formula_loader formula
fi = FormulaInstaller.new(formula) fi = described_class.new(formula)
fi.fetch fi.fetch
fi.install fi.install
@ -48,8 +48,7 @@ RSpec.describe FormulaInstaller do
expect(formula).not_to be_latest_version_installed expect(formula).not_to be_latest_version_installed
end end
def test_basic_formula_setup(formula) define_method(:test_basic_formula_setup) do |formula|
# Test that things made it into the Keg
expect(formula.bin).to be_a_directory expect(formula.bin).to be_a_directory
expect(formula.libexec).to be_a_directory expect(formula.libexec).to be_a_directory

View File

@ -16,7 +16,7 @@ RSpec.describe FormulaInstaller do
match(&:poured_from_bottle) match(&:poured_from_bottle)
end end
def temporary_install(formula, **options) define_method(:temporary_install) do |formula, **options|
expect(formula).not_to be_latest_version_installed expect(formula).not_to be_latest_version_installed
installer = described_class.new(formula, **options) installer = described_class.new(formula, **options)

View File

@ -676,7 +676,7 @@ RSpec.describe Formula do
f1 = formula do f1 = formula do
url "foo-1.0" url "foo-1.0"
def post_install define_method(:post_install) do
# do nothing # do nothing
end end
end end
@ -1146,7 +1146,7 @@ RSpec.describe Formula do
f = formula "foo" do f = formula "foo" do
url "foo-1.0" url "foo-1.0"
def pour_bottle? define_method(:pour_bottle?) do
false false
end end
end end
@ -1158,7 +1158,7 @@ RSpec.describe Formula do
f = formula "foo" do f = formula "foo" do
url "foo-1.0" url "foo-1.0"
def pour_bottle? define_method(:pour_bottle?) do
true true
end end
end end
@ -1362,7 +1362,7 @@ RSpec.describe Formula do
let(:alias_name) { "bar" } let(:alias_name) { "bar" }
let(:alias_path) { f.tap.alias_dir/alias_name } let(:alias_path) { f.tap.alias_dir/alias_name }
def setup_tab_for_prefix(prefix, options = {}) define_method(:setup_tab_for_prefix) do |prefix, options = {}|
prefix.mkpath prefix.mkpath
tab = Tab.empty tab = Tab.empty
tab.tabfile = prefix/AbstractTab::FILENAME tab.tabfile = prefix/AbstractTab::FILENAME
@ -1688,7 +1688,7 @@ RSpec.describe Formula do
Class.new(Testball) do Class.new(Testball) do
attr_reader :test attr_reader :test
def install define_method(:install) do
@test = 0 @test = 0
on_macos do on_macos do
@test = 1 @test = 1
@ -1711,7 +1711,7 @@ RSpec.describe Formula do
Class.new(Testball) do Class.new(Testball) do
attr_reader :test attr_reader :test
def install define_method(:install) do
@test = 0 @test = 0
on_macos do on_macos do
@test = 1 @test = 1
@ -1735,7 +1735,7 @@ RSpec.describe Formula do
attr_reader :foo attr_reader :foo
attr_reader :bar attr_reader :bar
def install define_method(:install) do
@foo = 0 @foo = 0
@bar = 0 @bar = 0
on_system :linux, macos: :monterey do on_system :linux, macos: :monterey do
@ -1794,7 +1794,7 @@ RSpec.describe Formula do
Class.new(Testball) do Class.new(Testball) do
attr_reader :test attr_reader :test
def install define_method(:install) do
@test = 0 @test = 0
on_monterey :or_newer do on_monterey :or_newer do
@test = 1 @test = 1
@ -1854,7 +1854,7 @@ RSpec.describe Formula do
Class.new(Testball) do Class.new(Testball) do
attr_reader :test attr_reader :test
def install define_method(:install) do
@test = 0 @test = 0
on_arm do on_arm do
@test = 1 @test = 1
@ -1881,7 +1881,7 @@ RSpec.describe Formula do
Class.new(Testball) do Class.new(Testball) do
attr_reader :test attr_reader :test
def install define_method(:install) do
@test = 0 @test = 0
on_arm do on_arm do
@test = 1 @test = 1
@ -1902,7 +1902,7 @@ RSpec.describe Formula do
describe "#generate_completions_from_executable" do describe "#generate_completions_from_executable" do
let(:f) do let(:f) do
Class.new(Testball) do Class.new(Testball) do
def install define_method(:install) do
bin.mkpath bin.mkpath
(bin/"foo").write <<-EOF (bin/"foo").write <<-EOF
echo completion echo completion

View File

@ -14,7 +14,7 @@ RSpec.describe Formula do
end.to raise_error(FormulaValidationError) end.to raise_error(FormulaValidationError)
end end
def supports_block_expectations? define_method(:supports_block_expectations?) do
true true
end end
end end
@ -22,7 +22,8 @@ RSpec.describe Formula do
it "can't override the `brew` method" do it "can't override the `brew` method" do
expect do expect do
formula do formula do
def brew; end define_method(:brew) do
end
end end
end.to raise_error(RuntimeError, /\AThe method `brew` on #{described_class} was declared as final/) end.to raise_error(RuntimeError, /\AThe method `brew` on #{described_class} was declared as final/)
end end

View File

@ -289,7 +289,7 @@ RSpec.describe Formulary do
end end
context "with the API" do context "with the API" do
def formula_json_contents(extra_items = {}) define_method(:formula_json_contents) do |extra_items = {}|
{ {
formula_name => { formula_name => {
"desc" => "testball", "desc" => "testball",

View File

@ -295,13 +295,13 @@ RSpec.describe GitHubRunnerMatrix, :no_api do
end end
end end
def get_runner_names(runner_matrix, predicate = :active) define_method(:get_runner_names) do |runner_matrix, predicate = :active|
runner_matrix.runners runner_matrix.runners
.select(&predicate) .select(&predicate)
.map { |runner| runner.spec.name } .map { |runner| runner.spec.name }
end end
def setup_test_runner_formula(name, dependencies = [], **kwargs) define_method(:setup_test_runner_formula) do |name, dependencies = [], **kwargs|
f = formula name do f = formula name do
url "https://brew.sh/#{name}-1.0.tar.gz" url "https://brew.sh/#{name}-1.0.tar.gz"
dependencies.each { |dependency| depends_on dependency } dependencies.each { |dependency| depends_on dependency }

View File

@ -5,7 +5,7 @@ require "installed_dependents"
RSpec.describe InstalledDependents do RSpec.describe InstalledDependents do
include FileUtils include FileUtils
def stub_formula(name, version = "1.0", &block) define_method(:stub_formula) do |name, version = "1.0", &block|
f = formula(name) do f = formula(name) do
url "#{name}-#{version}" url "#{name}-#{version}"
@ -16,7 +16,7 @@ RSpec.describe InstalledDependents do
f f
end end
def setup_test_keg(name, version, &block) define_method(:setup_test_keg) do |name, version, &block|
stub_formula("gcc") stub_formula("gcc")
stub_formula("glibc") stub_formula("glibc")
stub_formula(name, version, &block) stub_formula(name, version, &block)
@ -39,7 +39,7 @@ RSpec.describe InstalledDependents do
end end
describe "::find_some_installed_dependents" do describe "::find_some_installed_dependents" do
def setup_test_keg(name, version, &block) define_method(:setup_test_keg) do |_name, _version|
keg = super keg = super
Tab.create(keg.to_formula, DevelopmentTools.default_compiler, :libcxx).write Tab.create(keg.to_formula, DevelopmentTools.default_compiler, :libcxx).write
keg keg
@ -50,7 +50,7 @@ RSpec.describe InstalledDependents do
keg_only_keg.optlink keg_only_keg.optlink
end end
def alter_tab(keg) define_method(:alter_tab) do |keg|
tab = keg.tab tab = keg.tab
yield tab yield tab
tab.write tab.write
@ -58,7 +58,7 @@ RSpec.describe InstalledDependents do
# 1.1.6 is the earliest version of Homebrew that generates correct runtime # 1.1.6 is the earliest version of Homebrew that generates correct runtime
# dependency lists in {Tab}s. # dependency lists in {Tab}s.
def tab_dependencies(keg, deps, homebrew_version: "1.1.6") define_method(:tab_dependencies) do |keg, deps, homebrew_version: "1.1.6"|
alter_tab(keg) do |tab| alter_tab(keg) do |tab|
tab.homebrew_version = homebrew_version tab.homebrew_version = homebrew_version
tab.tabfile = keg/AbstractTab::FILENAME tab.tabfile = keg/AbstractTab::FILENAME
@ -66,7 +66,7 @@ RSpec.describe InstalledDependents do
end end
end end
def unreliable_tab_dependencies(keg, deps) define_method(:unreliable_tab_dependencies) do |keg, deps|
# 1.1.5 is (hopefully!) the last version of Homebrew that generates # 1.1.5 is (hopefully!) the last version of Homebrew that generates
# incorrect runtime dependency lists in {Tab}s. # incorrect runtime dependency lists in {Tab}s.
tab_dependencies(keg, deps, homebrew_version: "1.1.5") tab_dependencies(keg, deps, homebrew_version: "1.1.5")
@ -174,7 +174,7 @@ RSpec.describe InstalledDependents do
expect(described_class.find_some_installed_dependents([keg_only_keg])).to eq([[keg_only_keg], ["bar"]]) expect(described_class.find_some_installed_dependents([keg_only_keg])).to eq([[keg_only_keg], ["bar"]])
end end
def stub_cask_name(name, version, dependency) define_method(:stub_cask_name) do |name, version, dependency|
c = Cask::CaskLoader.load(<<-RUBY) c = Cask::CaskLoader.load(<<-RUBY)
cask "#{name}" do cask "#{name}" do
version "#{version}" version "#{version}"
@ -188,7 +188,7 @@ RSpec.describe InstalledDependents do
c c
end end
def setup_test_cask(name, version, dependency) define_method(:setup_test_cask) do |name, version, dependency|
c = stub_cask_name(name, version, dependency) c = stub_cask_name(name, version, dependency)
Cask::Caskroom.path.join(name, c.version).mkpath Cask::Caskroom.path.join(name, c.version).mkpath
c c

View File

@ -13,7 +13,7 @@ RSpec.describe Keg do
dir.mkpath dir.mkpath
end end
def setup_binary_file define_method(:setup_binary_file) do
binary_file.atomic_write <<~EOS binary_file.atomic_write <<~EOS
\x00#{dir}\x00 \x00#{dir}\x00
EOS EOS

View File

@ -13,7 +13,7 @@ RSpec.describe Keg do
dir.mkpath dir.mkpath
end end
def setup_text_file define_method(:setup_text_file) do
text_file.atomic_write <<~EOS text_file.atomic_write <<~EOS
#{dir}/file.txt #{dir}/file.txt
/foo#{dir}/file.txt /foo#{dir}/file.txt
@ -23,7 +23,7 @@ RSpec.describe Keg do
EOS EOS
end end
def setup_binary_file define_method(:setup_binary_file) do
binary_file.atomic_write <<~EOS binary_file.atomic_write <<~EOS
\x00 \x00
EOS EOS

View File

@ -14,7 +14,7 @@ RSpec.describe Keg::Relocation do
let(:escaped_prefix) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{Regexp.escape(HOMEBREW_PREFIX)}/o } let(:escaped_prefix) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{Regexp.escape(HOMEBREW_PREFIX)}/o }
let(:escaped_cellar) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{HOMEBREW_CELLAR}/o } let(:escaped_cellar) { /(?:(?<=-F|-I|-L|-isystem)|(?<![a-zA-Z0-9]))#{HOMEBREW_CELLAR}/o }
def setup_relocation define_method(:setup_relocation) do
relocation = described_class.new relocation = described_class.new
relocation.add_replacement_pair :prefix, prefix, prefix_placeholder, path: true relocation.add_replacement_pair :prefix, prefix, prefix_placeholder, path: true
relocation.add_replacement_pair :cellar, /#{cellar}/o, cellar_placeholder, path: true relocation.add_replacement_pair :cellar, /#{cellar}/o, cellar_placeholder, path: true

View File

@ -13,7 +13,7 @@ RSpec.describe Keg do
(HOMEBREW_CELLAR/"foo/1.0.0").mkpath (HOMEBREW_CELLAR/"foo/1.0.0").mkpath
end end
def setup_file(placeholders: false) define_method(:setup_file) do |placeholders: false|
path = placeholders ? placeholder : dir path = placeholders ? placeholder : dir
file.atomic_write <<~EOS file.atomic_write <<~EOS
#{path}/file.txt #{path}/file.txt
@ -24,7 +24,7 @@ RSpec.describe Keg do
EOS EOS
end end
def setup_relocation(placeholders: false) define_method(:setup_relocation) do |placeholders: false|
relocation = described_class::Relocation.new relocation = described_class::Relocation.new
if placeholders if placeholders

View File

@ -6,7 +6,7 @@ require "stringio"
RSpec.describe Keg do RSpec.describe Keg do
include FileUtils include FileUtils
def setup_test_keg(name, version) define_method(:setup_test_keg) do |name, version|
path = HOMEBREW_CELLAR/name/version path = HOMEBREW_CELLAR/name/version
(path/"bin").mkpath (path/"bin").mkpath

View File

@ -6,7 +6,7 @@ require "bundle_version"
RSpec.describe Homebrew::Livecheck::Strategy::Sparkle do RSpec.describe Homebrew::Livecheck::Strategy::Sparkle do
subject(:sparkle) { described_class } subject(:sparkle) { described_class }
def create_appcast_xml(items_str = "") define_method(:create_appcast_xml) do |items_str = ""|
<<~EOS <<~EOS
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle"> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">

View File

@ -8,7 +8,7 @@ RSpec.describe Pathname do
let(:sho_without_runpath_rpath) { elf_dir/"libhello.so.0" } let(:sho_without_runpath_rpath) { elf_dir/"libhello.so.0" }
let(:exec) { elf_dir/"hello_with_rpath" } let(:exec) { elf_dir/"hello_with_rpath" }
def patch_elfs define_method(:patch_elfs) do
mktmpdir do |tmp_dir| mktmpdir do |tmp_dir|
%w[c.elf].each do |elf| %w[c.elf].each do |elf|
FileUtils.cp(elf_dir/elf, tmp_dir/elf) FileUtils.cp(elf_dir/elf, tmp_dir/elf)

View File

@ -13,7 +13,7 @@
# #
# For indeterminable cases, consult https://opensource.apple.com for the version used. # For indeterminable cases, consult https://opensource.apple.com for the version used.
RSpec.describe "pkg-config", :needs_ci, type: :system do RSpec.describe "pkg-config", :needs_ci, type: :system do
def pc_version(library) define_method(:pc_version) do |library|
path = HOMEBREW_LIBRARY_PATH/"os/mac/pkgconfig/#{MacOS.version}/#{library}.pc" path = HOMEBREW_LIBRARY_PATH/"os/mac/pkgconfig/#{MacOS.version}/#{library}.pc"
version = File.foreach(path) version = File.foreach(path)
.lazy .lazy

View File

@ -25,7 +25,7 @@ RSpec.describe "patching", type: :system do
end end
end end
def formula(name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block) define_method(:formula) do |name = "formula_name", path: Formulary.core_path(name), spec: :stable, alias_path: nil, &block|
formula_subclass.class_eval(&block) formula_subclass.class_eval(&block)
formula_subclass.new(name, path, spec, alias_path:) formula_subclass.new(name, path, spec, alias_path:)
end end

View File

@ -5,7 +5,7 @@ require "rubocops/patches"
RSpec.describe RuboCop::Cop::FormulaAudit::Patches do RSpec.describe RuboCop::Cop::FormulaAudit::Patches do
subject(:cop) { described_class.new } subject(:cop) { described_class.new }
def expect_offense_hash(message:, severity:, line:, column:, source:) define_method(:expect_offense_hash) do |message:, severity:, line:, column:, source:|
[{ message:, severity:, line:, column:, source: }] [{ message:, severity:, line:, column:, source: }]
end end

View File

@ -12,7 +12,7 @@ RSpec.describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do
(path/"style_exceptions").mkpath (path/"style_exceptions").mkpath
end end
def setup_style_exceptions define_method(:setup_style_exceptions) do
(path/"style_exceptions/make_check_allowlist.json").write <<~JSON (path/"style_exceptions/make_check_allowlist.json").write <<~JSON
[ "bar" ] [ "bar" ]
JSON JSON

View File

@ -37,7 +37,7 @@ RSpec.describe Sandbox, :needs_macos do
url "https://brew.sh/foo-1.0.tar.gz" url "https://brew.sh/foo-1.0.tar.gz"
version "1.0" version "1.0"
def initialize(*, **) define_method(:initialize) do |*, **|
super super
@name = "foo)bar" @name = "foo)bar"
end end
@ -53,7 +53,7 @@ RSpec.describe Sandbox, :needs_macos do
url "https://brew.sh/foo-1.0.tar.gz" url "https://brew.sh/foo-1.0.tar.gz"
version "1.0" version "1.0"
def initialize(*, **) define_method(:initialize) do |*, **|
super super
@name = "foo\"bar" @name = "foo\"bar"
end end

View File

@ -6,7 +6,7 @@ require "service"
RSpec.describe Homebrew::Service do RSpec.describe Homebrew::Service do
let(:name) { "formula_name" } let(:name) { "formula_name" }
def stub_formula(&block) define_method(:stub_formula) do |&block|
formula(name) do formula(name) do
url "https://brew.sh/test-1.0.tbz" url "https://brew.sh/test-1.0.tbz"
@ -14,7 +14,7 @@ RSpec.describe Homebrew::Service do
end end
end end
def stub_formula_with_service_sockets(sockets_var) define_method(:stub_formula_with_service_sockets) do |sockets_var|
stub_formula do stub_formula do
service do service do
run opt_bin/"beanstalkd" run opt_bin/"beanstalkd"

View File

@ -9,7 +9,7 @@ RSpec.describe Homebrew::Settings do
end end
end end
def setup_setting define_method(:setup_setting) do
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
system "git", "config", "--replace-all", "homebrew.foo", "true" system "git", "config", "--replace-all", "homebrew.foo", "true"
end end

View File

@ -17,7 +17,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
status.success? status.success?
end end
def supports_block_expectations? define_method(:supports_block_expectations?) do
true true
end end
@ -37,7 +37,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
# }.to output(something).to_stdout # }.to output(something).to_stdout
# }.to be_a_success # }.to be_a_success
# #
def expects_call_stack_jump? define_method(:expects_call_stack_jump?) do
true true
end end
end end
@ -55,14 +55,14 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
# Generate unique ID to be able to # Generate unique ID to be able to
# properly merge coverage results. # properly merge coverage results.
def command_id define_method(:command_id) do
Thread.current[:brew_integration_test_number] ||= 0 Thread.current[:brew_integration_test_number] ||= 0
"#{ENV.fetch("TEST_ENV_NUMBER", "")}:#{Thread.current[:brew_integration_test_number] += 1}" "#{ENV.fetch("TEST_ENV_NUMBER", "")}:#{Thread.current[:brew_integration_test_number] += 1}"
end end
# Runs a `brew` command with the test configuration # Runs a `brew` command with the test configuration
# and with coverage reporting enabled. # and with coverage reporting enabled.
def brew(*args) define_method(:brew) do |*args|
env = args.last.is_a?(Hash) ? args.pop : {} env = args.last.is_a?(Hash) ? args.pop : {}
# Avoid warnings when HOMEBREW_PREFIX/bin is not in PATH. # Avoid warnings when HOMEBREW_PREFIX/bin is not in PATH.
@ -119,7 +119,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
end end
end end
def brew_sh(*args) define_method(:brew_sh) do |*args|
env = { env = {
"HOMEBREW_USE_RUBY_FROM_PATH" => ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", nil), "HOMEBREW_USE_RUBY_FROM_PATH" => ENV.fetch("HOMEBREW_USE_RUBY_FROM_PATH", nil),
} }
@ -131,8 +131,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
end end
end end
def setup_test_formula(name, content = nil, tap: CoreTap.instance, define_method(:setup_test_formula) do |name, content = nil, tap: CoreTap.instance, bottle_block: nil, tab_attributes: nil|
bottle_block: nil, tab_attributes: nil)
case name case name
when /^testball/ when /^testball/
# Use a different tarball for testball2 to avoid lock errors when writing concurrency tests # Use a different tarball for testball2 to avoid lock errors when writing concurrency tests
@ -205,7 +204,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
formula_path formula_path
end end
def install_test_formula(name, content = nil, build_bottle: false) define_method(:install_test_formula) do |name, content = nil, build_bottle: false|
setup_test_formula(name, content) setup_test_formula(name, content)
fi = FormulaInstaller.new(Formula[name], build_bottle:, installed_on_request: true) fi = FormulaInstaller.new(Formula[name], build_bottle:, installed_on_request: true)
fi.prelude fi.prelude
@ -214,7 +213,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
fi.finish fi.finish
end end
def setup_test_tap define_method(:setup_test_tap) do
path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo" path = HOMEBREW_TAP_DIRECTORY/"homebrew/homebrew-foo"
path.mkpath path.mkpath
path.cd do path.cd do
@ -227,7 +226,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
path path
end end
def setup_remote_tap(name) define_method(:setup_remote_tap) do |name|
Tap.fetch(name).tap do |tap| Tap.fetch(name).tap do |tap|
next if tap.installed? next if tap.installed?
@ -243,7 +242,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
end end
end end
def install_and_rename_coretap_formula(old_name, new_name) define_method(:install_and_rename_coretap_formula) do |old_name, new_name|
CoreTap.instance.path.cd do |tap_path| CoreTap.instance.path.cd do |tap_path|
system "git", "init" system "git", "init"
system "git", "add", "--all" system "git", "add", "--all"
@ -261,7 +260,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
end end
end end
def testball define_method(:testball) do
"#{TEST_FIXTURE_DIR}/testball.rb" "#{TEST_FIXTURE_DIR}/testball.rb"
end end
end end

View File

@ -24,7 +24,7 @@ RSpec.describe Tap do
(path/"style_exceptions").mkpath (path/"style_exceptions").mkpath
end end
def setup_tap_files define_method(:setup_tap_files) do
formula_file.dirname.mkpath formula_file.dirname.mkpath
formula_file.write <<~RUBY formula_file.write <<~RUBY
class Foo < Formula class Foo < Formula
@ -80,7 +80,7 @@ RSpec.describe Tap do
chmod 0755, cmd_file chmod 0755, cmd_file
end end
def setup_git_repo define_method(:setup_git_repo) do
path.cd do path.cd do
system "git", "init" system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
@ -89,7 +89,7 @@ RSpec.describe Tap do
end end
end end
def setup_completion(link:) define_method(:setup_completion) do |link:|
HOMEBREW_REPOSITORY.cd do HOMEBREW_REPOSITORY.cd do
system "git", "init" system "git", "init"
system "git", "config", "--replace-all", "homebrew.linkcompletions", link.to_s system "git", "config", "--replace-all", "homebrew.linkcompletions", link.to_s

View File

@ -403,7 +403,7 @@ RSpec.describe TestRunnerFormula do
end end
end end
def setup_test_formula(name, dependencies = [], **kwargs) define_method(:setup_test_formula) do |name, dependencies = [], **kwargs|
formula name do formula name do
url "https://brew.sh/#{name}-1.0.tar.gz" url "https://brew.sh/#{name}-1.0.tar.gz"
dependencies.each { |dependency| depends_on dependency } dependencies.each { |dependency| depends_on dependency }

View File

@ -50,7 +50,7 @@ RSpec.describe Utils::Backtrace do
backtrace_with_sorbet_paths.drop(1) backtrace_with_sorbet_paths.drop(1)
end end
def exception_with(backtrace:) define_method(:exception_with) do |backtrace:|
exception = StandardError.new exception = StandardError.new
exception.set_backtrace(backtrace) if backtrace exception.set_backtrace(backtrace) if backtrace
exception exception

View File

@ -29,7 +29,7 @@ RSpec.describe SharedAudits do
JSON JSON
end end
def mock_curl_output(stdout: "", success: true) define_method(:mock_curl_output) do |stdout: "", success: true|
status = instance_double(Process::Status, success?: success) status = instance_double(Process::Status, success?: success)
curl_output = instance_double(SystemCommand::Result, stdout:, status:) curl_output = instance_double(SystemCommand::Result, stdout:, status:)
allow(Utils::Curl).to receive(:curl_output).and_return curl_output allow(Utils::Curl).to receive(:curl_output).and_return curl_output

View File

@ -48,7 +48,7 @@ module Homebrew
if rack.directory? if rack.directory?
versions = rack.subdirs.map(&:basename) versions = rack.subdirs.map(&:basename)
puts <<~EOS puts <<~EOS
#{keg.name} #{versions.to_sentence} #{(versions.one?) ? "is" : "are"} still installed. #{keg.name} #{versions.to_sentence} #{versions.one? ? "is" : "are"} still installed.
To remove all versions, run: To remove all versions, run:
brew uninstall --force #{keg.name} brew uninstall --force #{keg.name}
EOS EOS
@ -133,7 +133,7 @@ module Homebrew
def output def output
ofail <<~EOS ofail <<~EOS
Refusing to uninstall #{reqs.to_sentence} Refusing to uninstall #{reqs.to_sentence}
because #{(reqs.one?) ? "it" : "they"} #{are_required_by_deps}. because #{reqs.one? ? "it" : "they"} #{are_required_by_deps}.
You can override this and force removal with: You can override this and force removal with:
#{sample_command} #{sample_command}
EOS EOS
@ -146,8 +146,8 @@ module Homebrew
end end
def are_required_by_deps def are_required_by_deps
"#{(reqs.one?) ? "is" : "are"} required by #{deps.to_sentence}, " \ "#{reqs.one? ? "is" : "are"} required by #{deps.to_sentence}, " \
"which #{(deps.one?) ? "is" : "are"} currently installed" "which #{deps.one? ? "is" : "are"} currently installed"
end end
end end

View File

@ -445,7 +445,7 @@ module Utils
format "%#{index_width}s", index_header format "%#{index_width}s", index_header
formatted_name_with_options_header = formatted_name_with_options_header =
format "%-#{name_with_options_width}s", format "%-#{name_with_options_width}s",
name_with_options_header[0..name_with_options_width-1] name_with_options_header[0..(name_with_options_width-1)]
formatted_count_header = formatted_count_header =
format "%#{count_width}s", count_header format "%#{count_width}s", count_header
formatted_percent_header = formatted_percent_header =
@ -464,7 +464,7 @@ module Utils
formatted_index = format "%-#{index_width}s", formatted_index formatted_index = format "%-#{index_width}s", formatted_index
formatted_name_with_options = formatted_name_with_options =
format "%-#{name_with_options_width}s", format "%-#{name_with_options_width}s",
name_with_options[0..name_with_options_width-1] name_with_options[0..(name_with_options_width-1)]
formatted_count = format "%#{count_width}s", format_count(count) formatted_count = format "%#{count_width}s", format_count(count)
formatted_percent = if total_count.zero? formatted_percent = if total_count.zero?
format "%#{percent_width}s", format_percent(0) format "%#{percent_width}s", format_percent(0)

View File

@ -776,6 +776,6 @@ class Version
sig { params(first: Integer, second: Integer).returns(Integer) } sig { params(first: Integer, second: Integer).returns(Integer) }
def max(first, second) def max(first, second)
(first > second) ? first : second [first, second].max
end end
end end