diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 8c0870c4ec..1b4a5309d0 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -275,6 +275,7 @@ module Cask @ruby_source_path = sourcefile_path.relative_path_from(tap.path) end + sig { returns(T::Hash[Symbol, String]) } def ruby_source_checksum @ruby_source_checksum ||= { sha256: Digest::SHA256.file(sourcefile_path).hexdigest, @@ -300,7 +301,7 @@ module Cask # TODO: Clean this up when we deprecate the current JSON API and move to the internal JSON v3. ruby_source_sha256 = json_cask.dig(:ruby_source_checksum, :sha256) ruby_source_sha256 ||= json_cask[:ruby_source_sha256] - @ruby_source_checksum = { "sha256" => ruby_source_sha256 } + @ruby_source_checksum = { sha256: ruby_source_sha256 } end def to_s diff --git a/Library/Homebrew/test/api/cask_spec.rb b/Library/Homebrew/test/api/cask_spec.rb index 6758e1671c..a3d787993c 100644 --- a/Library/Homebrew/test/api/cask_spec.rb +++ b/Library/Homebrew/test/api/cask_spec.rb @@ -45,4 +45,30 @@ RSpec.describe Homebrew::API::Cask do expect(casks_output).to eq casks_hash end end + + describe "::source_download", :needs_macos do + let(:cask) do + cask = Cask::CaskLoader::FromAPILoader.new( + "everything", + from_json: JSON.parse((TEST_FIXTURE_DIR/"cask/everything.json").read.strip), + ).load(config: nil) + cask + end + + before do + allow_any_instance_of(Homebrew::API::Download).to receive(:fetch) + allow_any_instance_of(Homebrew::API::Download).to receive(:symlink_location).and_return( + TEST_FIXTURE_DIR/"cask/Casks/everything.rb", + ) + end + + it "specifies the correct URL and sha256" do + expect(Homebrew::API::Download).to receive(:new).with( + "https://raw.githubusercontent.com/Homebrew/homebrew-cask/abcdef1234567890abcdef1234567890abcdef12/Casks/everything.rb", + Checksum.new("d8d0d6b2e5ff65388eccb82236fd3aa157b4a29bb043a1f72b97f0e9b70e8320"), + any_args, + ).and_call_original + described_class.source_download(cask) + end + end end diff --git a/Library/Homebrew/test/cask/cask_spec.rb b/Library/Homebrew/test/cask/cask_spec.rb index fea5589a37..1cadf13a03 100644 --- a/Library/Homebrew/test/cask/cask_spec.rb +++ b/Library/Homebrew/test/cask/cask_spec.rb @@ -219,7 +219,11 @@ RSpec.describe Cask::Cask, :cask do it "returns expected hash" do allow(MacOS).to receive(:version).and_return(MacOSVersion.new("13")) - hash = Cask::CaskLoader.load("everything").to_h + cask = Cask::CaskLoader.load("everything") + + expect(cask.tap).to receive(:git_head).and_return("abcdef1234567890abcdef1234567890abcdef12") + + hash = cask.to_h expect(hash).to be_a(Hash) expect(JSON.pretty_generate(hash)).to eq(expected_json) diff --git a/Library/Homebrew/test/support/fixtures/cask/everything.json b/Library/Homebrew/test/support/fixtures/cask/everything.json index 59bebe0635..e17f57afed 100644 --- a/Library/Homebrew/test/support/fixtures/cask/everything.json +++ b/Library/Homebrew/test/support/fixtures/cask/everything.json @@ -96,7 +96,7 @@ "disabled": false, "disable_date": null, "disable_reason": null, - "tap_git_head": null, + "tap_git_head": "abcdef1234567890abcdef1234567890abcdef12", "languages": [ "en", "eo"