| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  | require "livecheck/strategy" | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe Homebrew::Livecheck::Strategy::Cpan do | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  |   subject(:cpan) { described_class } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   let(:cpan_urls) do | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |       no_subdirectory:   "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/Brew-v1.2.3.tar.gz", | 
					
						
							|  |  |  |       with_subdirectory: "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/brew/brew-v1.2.3.tar.gz", | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  |   let(:non_cpan_url) { "https://brew.sh/test" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   let(:generated) do | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  |     { | 
					
						
							|  |  |  |       no_subdirectory:   { | 
					
						
							|  |  |  |         url:   "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/", | 
					
						
							|  |  |  |         regex: /href=.*?Brew[._-]v?(\d+(?:\.\d+)*)\.t/i, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |       with_subdirectory: { | 
					
						
							|  |  |  |         url:   "https://cpan.metacpan.org/authors/id/H/HO/HOMEBREW/brew/", | 
					
						
							|  |  |  |         regex: /href=.*?brew[._-]v?(\d+(?:\.\d+)*)\.t/i, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  |   describe "::match?" do | 
					
						
							| 
									
										
										
										
											2021-08-10 17:39:11 -04:00
										 |  |  |     it "returns true for a CPAN URL" do | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  |       expect(cpan.match?(cpan_urls[:no_subdirectory])).to be true | 
					
						
							|  |  |  |       expect(cpan.match?(cpan_urls[:with_subdirectory])).to be true | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-10 17:39:11 -04:00
										 |  |  |     it "returns false for a non-CPAN URL" do | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  |       expect(cpan.match?(non_cpan_url)).to be false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2021-07-28 13:20:12 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "::generate_input_values" do | 
					
						
							|  |  |  |     it "returns a hash containing url and regex for a CPAN URL" do | 
					
						
							|  |  |  |       expect(cpan.generate_input_values(cpan_urls[:no_subdirectory])).to eq(generated[:no_subdirectory]) | 
					
						
							|  |  |  |       expect(cpan.generate_input_values(cpan_urls[:with_subdirectory])).to eq(generated[:with_subdirectory]) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "returns an empty hash for a non-CPAN URL" do | 
					
						
							|  |  |  |       expect(cpan.generate_input_values(non_cpan_url)).to eq({}) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-12-11 04:31:14 +01:00
										 |  |  | end |