diff --git a/Library/Homebrew/test/utils/spdx_spec.rb b/Library/Homebrew/test/utils/spdx_spec.rb new file mode 100644 index 0000000000..e99cc5e610 --- /dev/null +++ b/Library/Homebrew/test/utils/spdx_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require "utils/spdx" + +describe SPDX do + describe ".spdx_data" do + it "has the license list version" do + expect(described_class.spdx_data["licenseListVersion"]).not_to eq(nil) + end + + it "has the release date" do + expect(described_class.spdx_data["releaseDate"]).not_to eq(nil) + end + + it "has licenses" do + expect(described_class.spdx_data["licenses"].length).not_to eq(0) + end + end + + describe ".download_latest_license_data!", :needs_network do + let(:tmp_json_path) { Pathname.new("#{TEST_TMPDIR}/spdx.json") } + + after do + FileUtils.rm tmp_json_path + end + + it "downloads latest license data" do + described_class.download_latest_license_data! to: tmp_json_path + expect(tmp_json_path).to exist + end + end +end diff --git a/Library/Homebrew/utils/spdx.rb b/Library/Homebrew/utils/spdx.rb index a2c5fd4f12..4ee6b59eb4 100644 --- a/Library/Homebrew/utils/spdx.rb +++ b/Library/Homebrew/utils/spdx.rb @@ -12,9 +12,9 @@ module SPDX @spdx_data ||= JSON.parse(JSON_PATH.read) end - def download_latest_license_data! + def download_latest_license_data!(to: JSON_PATH) latest_tag = GitHub.open_api(API_URL)["tag_name"] data_url = "https://raw.githubusercontent.com/spdx/license-list-data/#{latest_tag}/json/licenses.json" - curl_download(data_url, to: JSON_PATH, partial: false) + curl_download(data_url, to: to, partial: false) end end