Skip to content

Commit

Permalink
Fixes for Ruby 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Sep 29, 2023
1 parent 71f5582 commit af7d744
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class AbstractUninstall < AbstractArtifact
].freeze

def self.from_args(cask, **directives)
new(cask, directives)
new(cask, **directives)
end

attr_reader :directives

def initialize(cask, directives)
def initialize(cask, **directives)
directives.assert_valid_keys(*ORDERED_DIRECTIVES)

super(cask, **directives)
Expand Down
8 changes: 7 additions & 1 deletion Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,13 @@ def load(config:)
# for artifacts with blocks that can't be loaded from the API
send(key) {} # empty on purpose
else
send(key, *artifact[key])
args = artifact[key]
kwargs = if args.last.is_a?(Hash)
args.pop
else
{}
end
send(key, *args, **kwargs)
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def readall
end

taps.each do |tap|
Homebrew.failed = true unless Readall.valid_tap?(tap, options)
Homebrew.failed = true unless Readall.valid_tap?(tap, **options)
end
end
end
6 changes: 2 additions & 4 deletions Library/Homebrew/test/cli/named_args_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

def setup_unredable_formula(name)
error = FormulaUnreadableError.new(name, RuntimeError.new("testing"))
allow(Formulary).to receive(:factory).with(name, {}).and_raise(error)
allow(Formulary).to receive(:factory).with(name, any_args).and_raise(error)
end

def setup_unredable_cask(name)
error = Cask::CaskUnreadableError.new(name, "testing")
allow(Cask::CaskLoader).to receive(:load).with(name).and_raise(error)
allow(Cask::CaskLoader).to receive(:load).with(name, config: nil).and_raise(error)
allow(Cask::CaskLoader).to receive(:load).with(name, any_args).and_raise(error)

config = instance_double(Cask::Config)
allow(Cask::Config).to receive(:from_args).and_return(config)
allow(Cask::CaskLoader).to receive(:load).with(name, config: config).and_raise(error)
end

describe Homebrew::CLI::NamedArgs do
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/test/dev-cmd/irb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
.and not_to_output.to_stderr
.and be_a_success

expect(history_file).to exist
# TODO: newer Ruby only supports history saving in interactive sessions
# and not if you feed in data from a file or stdin like we are doing here.
# The test will need to be adjusted for this to work.
expect(history_file).to exist if RUBY_VERSION < "2.7"
end
end
end
3 changes: 1 addition & 2 deletions Library/Homebrew/test/support/helper/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def stub_formula_loader(formula, ref = formula.full_name, call_original: false)
allow(Formulary).to receive(:loader_for).and_call_original if call_original

loader = double(get_formula: formula)
allow(Formulary).to receive(:loader_for).with(ref, from: :keg, warn: false).and_return(loader)
allow(Formulary).to receive(:loader_for).with(ref, {}).and_return(loader)
allow(Formulary).to receive(:loader_for).with(ref, any_args).and_return(loader)
end
end
end
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/test/test_runner_formula_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@

context "when a formula has no dependents" do
it "returns an empty array" do
expect(described_class.new(testball).dependents(current_system)).to eq([])
expect(described_class.new(xcode_helper).dependents(current_system)).to eq([])
expect(described_class.new(linux_kernel_requirer).dependents(current_system)).to eq([])
expect(described_class.new(old_non_portable_software).dependents(current_system)).to eq([])
expect(described_class.new(fancy_new_software).dependents(current_system)).to eq([])
expect(described_class.new(needs_modern_compiler).dependents(current_system)).to eq([])
expect(described_class.new(testball).dependents(**current_system)).to eq([])
expect(described_class.new(xcode_helper).dependents(**current_system)).to eq([])
expect(described_class.new(linux_kernel_requirer).dependents(**current_system)).to eq([])
expect(described_class.new(old_non_portable_software).dependents(**current_system)).to eq([])
expect(described_class.new(fancy_new_software).dependents(**current_system)).to eq([])
expect(described_class.new(needs_modern_compiler).dependents(**current_system)).to eq([])
end
end

Expand All @@ -313,11 +313,11 @@
allow(Formula).to receive(:all).and_return([testball_user, recursive_testball_dependent])

expect(
described_class.new(testball, eval_all: true).dependents(current_system).map(&:name),
described_class.new(testball, eval_all: true).dependents(**current_system).map(&:name),
).to eq(["testball_user"])

expect(
described_class.new(testball_user, eval_all: true).dependents(current_system).map(&:name),
described_class.new(testball_user, eval_all: true).dependents(**current_system).map(&:name),
).to eq(["recursive_testball_dependent"])
end

Expand Down

0 comments on commit af7d744

Please sign in to comment.