Skip to content

Commit

Permalink
code review changes (for: removal of greedy cask prefetching)
Browse files Browse the repository at this point in the history
  • Loading branch information
jneubrand committed Feb 20, 2024
1 parent b0ff1bd commit 3188778
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
11 changes: 6 additions & 5 deletions lib/bundle/cask_dumper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ def outdated_cask_names
.map(&:to_s)
end

def cask_is_outdated_using_greedy(cask)
return [] unless Bundle.cask_installed?
def cask_is_outdated_using_greedy?(cask_name)
return false unless Bundle.cask_installed?

cask = casks.find { |c| c.to_s == cask_name }
return false if cask.nil?

casks.select { |c| c.to_s == cask }
.map { |c| c.outdated?(greedy: true) }
.first
cask.outdated?(greedy: true)
end

def cask_versions
Expand Down
2 changes: 1 addition & 1 deletion lib/bundle/cask_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def upgrading?(no_upgrade, name, options)
return true if outdated_casks.include?(name)
return false unless options[:greedy]

Bundle::CaskDumper.cask_is_outdated_using_greedy(name)
Bundle::CaskDumper.cask_is_outdated_using_greedy?(name)
end

def preinstall(name, no_upgrade: false, verbose: false, **options)
Expand Down
32 changes: 26 additions & 6 deletions spec/bundle/cask_dumper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
it "dumps as empty string" do
expect(dumper.dump).to eql("")
end

it "doesn’t want to greedily update a non-installed cask" do
expect(dumper.cask_is_outdated_using_greedy?("foo")).to be(false)
end
end

context "when casks `foo`, `bar` and `baz` are installed, with `baz` being a formula requirement" do
before do
described_class.reset!

foo = instance_double(Cask::Cask, to_s: "foo", desc: nil, config: nil)
baz = instance_double(Cask::Cask, to_s: "baz", desc: "Software", config: nil)
bar = instance_double(
let(:foo) { instance_double(Cask::Cask, to_s: "foo", desc: nil, config: nil) }
let(:baz) { instance_double(Cask::Cask, to_s: "baz", desc: "Software", config: nil) }
let(:bar) do
instance_double(
Cask::Cask, to_s: "bar",
desc: nil,
config: instance_double(Cask::Config,
Expand All @@ -53,6 +55,10 @@
},
explicit_s: 'fontdir: "/Library/Fonts", language: "zh-TW"')
)
end

before do
described_class.reset!

allow(Bundle).to receive(:cask_installed?).and_return(true)
allow(Cask::Caskroom).to receive(:casks).and_return([foo, bar, baz])
Expand All @@ -71,6 +77,20 @@
EOS
expect(dumper.dump(describe: true)).to eql(expected.chomp)
end

it "doesn’t want to greedily update a non-installed cask" do
expect(dumper.cask_is_outdated_using_greedy?("qux")).to be(false)
end

it "wants to greedily update foo if there is an update available" do
expect(foo).to receive(:outdated?).with(greedy: true).and_return(true)
expect(dumper.cask_is_outdated_using_greedy?("foo")).to be(true)
end

it "does not want to greedily update bar if there is no updated available" do
expect(bar).to receive(:outdated?).with(greedy: true).and_return(false)
expect(dumper.cask_is_outdated_using_greedy?("bar")).to be(false)
end
end

describe "#formula_dependencies" do
Expand Down
2 changes: 1 addition & 1 deletion spec/bundle/cask_installer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
context "when cask is outdated and uses auto-update" do
before do
allow(Bundle::CaskDumper).to receive_messages(cask_names: ["opera"], outdated_cask_names: [])
allow(Bundle::CaskDumper).to receive(:cask_is_outdated_using_greedy).with("opera").and_return(true)
allow(Bundle::CaskDumper).to receive(:cask_is_outdated_using_greedy?).with("opera").and_return(true)
end

it "upgrades" do
Expand Down
4 changes: 4 additions & 0 deletions spec/stub/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ def depends_on
def config
nil
end

def outdated?(greedy: false)
false
end
end
end

0 comments on commit 3188778

Please sign in to comment.