| 
									
										
										
										
											2023-12-01 19:19:43 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "formula_creator" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Homebrew::FormulaCreator do | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |   describe ".new" do | 
					
						
							|  |  |  |     tests = { | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "generic tarball URL":             { | 
					
						
							|  |  |  |         url:              "http://digit-labs.org/files/tools/synscan/releases/synscan-5.02.tar.gz", | 
					
						
							|  |  |  |         expected_name:    "synscan", | 
					
						
							|  |  |  |         expected_version: "5.02", | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "gitweb URL":                      { | 
					
						
							|  |  |  |         url:           "http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary", | 
					
						
							|  |  |  |         expected_name: "libzipper", | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "GitHub repository URL with .git": { | 
					
						
							|  |  |  |         url:                    "https://github.com/Homebrew/brew.git", | 
					
						
							|  |  |  |         fetch:                  true, | 
					
						
							|  |  |  |         github_user_repository: ["Homebrew", "brew"], | 
					
						
							|  |  |  |         expected_name:          "brew", | 
					
						
							|  |  |  |         expected_head:          true, | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "GitHub archive URL":              { | 
					
						
							|  |  |  |         url:                    "https://github.com/Homebrew/brew/archive/4.5.7.tar.gz", | 
					
						
							|  |  |  |         fetch:                  true, | 
					
						
							|  |  |  |         github_user_repository: ["Homebrew", "brew"], | 
					
						
							|  |  |  |         expected_name:          "brew", | 
					
						
							|  |  |  |         expected_version:       "4.5.7", | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "GitHub releases URL":             { | 
					
						
							|  |  |  |         url:                    "https://github.com/stella-emu/stella/releases/download/6.7/stella-6.7-src.tar.xz", | 
					
						
							|  |  |  |         fetch:                  true, | 
					
						
							|  |  |  |         github_user_repository: ["stella-emu", "stella"], | 
					
						
							|  |  |  |         expected_name:          "stella", | 
					
						
							|  |  |  |         expected_version:       "6.7", | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |       "GitHub latest release":           { | 
					
						
							|  |  |  |         url:                    "https://github.com/buildpacks/pack", | 
					
						
							|  |  |  |         fetch:                  true, | 
					
						
							|  |  |  |         github_user_repository: ["buildpacks", "pack"], | 
					
						
							|  |  |  |         latest_release:         { "tag_name" => "v0.37.0" }, | 
					
						
							|  |  |  |         expected_name:          "pack", | 
					
						
							| 
									
										
										
										
											2025-06-23 12:23:46 +03:00
										 |  |  |         expected_url:           "https://github.com/buildpacks/pack/archive/refs/tags/v0.37.0.tar.gz", | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |         expected_version:       "v0.37.0", | 
					
						
							| 
									
										
										
										
											2025-06-18 05:40:40 +03:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-19 16:28:48 +03:00
										 |  |  |       "GitHub URL with name override":   { | 
					
						
							|  |  |  |         url:           "https://github.com/RooVetGit/Roo-Code", | 
					
						
							|  |  |  |         name:          "roo", | 
					
						
							|  |  |  |         expected_name: "roo", | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-12-01 19:19:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |     tests.each do |description, test| | 
					
						
							|  |  |  |       it "parses #{description}" do | 
					
						
							| 
									
										
										
										
											2025-06-18 15:07:44 +01:00
										 |  |  |         fetch = test.fetch(:fetch, false) | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |         if fetch | 
					
						
							|  |  |  |           github_user_repository = test.fetch(:github_user_repository) | 
					
						
							|  |  |  |           allow(GitHub).to receive(:repository).with(*github_user_repository) | 
					
						
							|  |  |  |           if (latest_release = test[:latest_release]) | 
					
						
							|  |  |  |             expect(GitHub).to receive(:get_latest_release).with(*github_user_repository).and_return(latest_release) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2025-06-18 05:40:40 +03:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2025-06-18 15:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-19 16:28:48 +03:00
										 |  |  |         formula_creator = described_class.new(url: test.fetch(:url), name: test[:name], fetch:) | 
					
						
							| 
									
										
										
										
											2025-06-18 15:07:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |         expect(formula_creator.name).to eq(test.fetch(:expected_name)) | 
					
						
							|  |  |  |         if (expected_version = test[:expected_version]) | 
					
						
							|  |  |  |           expect(formula_creator.version).to eq(expected_version) | 
					
						
							| 
									
										
										
										
											2025-06-17 11:44:15 +01:00
										 |  |  |         else | 
					
						
							|  |  |  |           expect(formula_creator.version).to be_null | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2025-06-23 12:23:46 +03:00
										 |  |  |         if (expected_url = test[:expected_url]) | 
					
						
							|  |  |  |           expect(formula_creator.url).to eq(expected_url) | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2025-06-19 09:02:27 +01:00
										 |  |  |         expect(formula_creator.head).to eq(test.fetch(:expected_head, false)) | 
					
						
							| 
									
										
										
										
											2025-06-15 15:28:43 +03:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2023-12-01 19:19:43 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |