From 014b603b1f7c4731e1de0ebd27355f186438e285 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sat, 28 Jan 2023 02:15:05 -0600 Subject: [PATCH] Fix tests --- Library/Homebrew/test/api/cask_spec.rb | 10 ++++++++++ Library/Homebrew/test/api_spec.rb | 21 +++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/test/api/cask_spec.rb b/Library/Homebrew/test/api/cask_spec.rb index 35c561b8f9..b5dd7ec1f2 100644 --- a/Library/Homebrew/test/api/cask_spec.rb +++ b/Library/Homebrew/test/api/cask_spec.rb @@ -41,4 +41,14 @@ describe Homebrew::API::Cask do expect(casks_output).to eq casks_hash end end + + describe "::fetch_source" do + it "fetches the source of a cask (defaulting to master when no `git_head` is passed)" do + curl_output = OpenStruct.new(stdout: "foo", success?: true) + expect(Utils::Curl).to receive(:curl_output) + .with("--fail", "https://raw.githubusercontent.com/Homebrew/homebrew-cask/master/Casks/foo.rb", max_time: 5) + .and_return(curl_output) + described_class.fetch_source("foo", git_head: nil) + end + end end diff --git a/Library/Homebrew/test/api_spec.rb b/Library/Homebrew/test/api_spec.rb index ff695bfe77..6d639e5c0f 100644 --- a/Library/Homebrew/test/api_spec.rb +++ b/Library/Homebrew/test/api_spec.rb @@ -21,12 +21,6 @@ describe Homebrew::API do end describe "::fetch" do - it "fetches a text file" do - mock_curl_output stdout: text - fetched_text = described_class.fetch("foo.txt", json: false) - expect(fetched_text).to eq text - end - it "fetches a JSON file" do mock_curl_output stdout: json fetched_json = described_class.fetch("foo.json") @@ -70,4 +64,19 @@ describe Homebrew::API do }.to raise_error(SystemExit) end end + + describe "::fetch_file_source" do + it "fetches a file" do + mock_curl_output stdout: json + fetched_json = described_class.fetch_file_source("foo.json", repo: "Homebrew/homebrew-core", git_head: "master") + expect(fetched_json).to eq json + end + + it "raises an error if the file does not exist" do + mock_curl_output success: false + expect { + described_class.fetch_file_source("bar.txt", repo: "Homebrew/homebrew-core", git_head: "master") + }.to raise_error(ArgumentError, /No file found/) + end + end end