Rename load method when preferring installed casks

This commit is contained in:
Rylan Polster 2024-09-10 13:54:12 -04:00
parent 711d2220b8
commit b1db0ee290
No known key found for this signature in database
3 changed files with 8 additions and 8 deletions

View File

@ -612,7 +612,7 @@ module Cask
end end
sig { params(ref: String, config: T.nilable(Config), warn: T::Boolean).returns(Cask) } sig { params(ref: String, config: T.nilable(Config), warn: T::Boolean).returns(Cask) }
def self.load_installed_cask(ref, config: nil, warn: true) def self.load_prefer_installed(ref, config: nil, warn: true)
tap, token = Tap.with_cask_token(ref) tap, token = Tap.with_cask_token(ref)
token ||= ref token ||= ref
tap ||= Cask.new(ref).tab.tap tap ||= Cask.new(ref).tab.tap

View File

@ -56,7 +56,7 @@ module Cask
sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) } sig { params(config: T.nilable(Config)).returns(T::Array[Cask]) }
def self.casks(config: nil) def self.casks(config: nil)
tokens.sort.filter_map do |token| tokens.sort.filter_map do |token|
CaskLoader.load_installed_cask(token, config:, warn: false) CaskLoader.load_prefer_installed(token, config:, warn: false)
rescue TapCaskAmbiguityError => e rescue TapCaskAmbiguityError => e
T.must(e.loaders.first).load(config:) T.must(e.loaders.first).load(config:)
rescue rescue

View File

@ -185,7 +185,7 @@ RSpec.describe Cask::CaskLoader, :cask do
end end
end end
describe "::load_installed_cask" do describe "::load_prefer_installed" do
let(:foo_tap) { Tap.fetch("user", "foo") } let(:foo_tap) { Tap.fetch("user", "foo") }
let(:bar_tap) { Tap.fetch("user", "bar") } let(:bar_tap) { Tap.fetch("user", "bar") }
@ -207,28 +207,28 @@ RSpec.describe Cask::CaskLoader, :cask do
allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(blank_tab) allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(blank_tab)
expect(described_class).to receive(:load).with("test-cask", load_args) expect(described_class).to receive(:load).with("test-cask", load_args)
expect(described_class.load_installed_cask("test-cask").tap).to eq(foo_tap) expect(described_class.load_prefer_installed("test-cask").tap).to eq(foo_tap)
end end
it "returns the correct cask when no tap is specified but a tab exists" do it "returns the correct cask when no tap is specified but a tab exists" do
allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(installed_tab) allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(installed_tab)
expect(described_class).to receive(:load).with("user/bar/test-cask", load_args) expect(described_class).to receive(:load).with("user/bar/test-cask", load_args)
expect(described_class.load_installed_cask("test-cask").tap).to eq(bar_tap) expect(described_class.load_prefer_installed("test-cask").tap).to eq(bar_tap)
end end
it "returns the correct cask when a tap is specified and no tab exists" do it "returns the correct cask when a tap is specified and no tab exists" do
allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(blank_tab) allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(blank_tab)
expect(described_class).to receive(:load).with("user/bar/test-cask", load_args) expect(described_class).to receive(:load).with("user/bar/test-cask", load_args)
expect(described_class.load_installed_cask("user/bar/test-cask").tap).to eq(bar_tap) expect(described_class.load_prefer_installed("user/bar/test-cask").tap).to eq(bar_tap)
end end
it "returns the correct cask when no tap is specified and a tab exists" do it "returns the correct cask when no tap is specified and a tab exists" do
allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(installed_tab) allow_any_instance_of(Cask::Cask).to receive(:tab).and_return(installed_tab)
expect(described_class).to receive(:load).with("user/foo/test-cask", load_args) expect(described_class).to receive(:load).with("user/foo/test-cask", load_args)
expect(described_class.load_installed_cask("user/foo/test-cask").tap).to eq(foo_tap) expect(described_class.load_prefer_installed("user/foo/test-cask").tap).to eq(foo_tap)
end end
it "returns the correct cask when no tap is specified and the tab lists an tap that isn't installed" do it "returns the correct cask when no tap is specified and the tab lists an tap that isn't installed" do
@ -237,7 +237,7 @@ RSpec.describe Cask::CaskLoader, :cask do
.and_raise(Cask::CaskUnavailableError.new("test-cask", bar_tap)) .and_raise(Cask::CaskUnavailableError.new("test-cask", bar_tap))
expect(described_class).to receive(:load).with("test-cask", load_args) expect(described_class).to receive(:load).with("test-cask", load_args)
expect(described_class.load_installed_cask("test-cask").tap).to eq(foo_tap) expect(described_class.load_prefer_installed("test-cask").tap).to eq(foo_tap)
end end
end end
end end