| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "download_strategy" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe DownloadStrategyDetector do | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |   describe "::detect" do | 
					
						
							|  |  |  |     subject(:strategy_detector) { described_class.detect(url, strategy) } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-12 11:39:01 -07:00
										 |  |  |     let(:url) { "invalidurl" } | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     let(:strategy) { nil } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     context "when given Git URL" do | 
					
						
							|  |  |  |       let(:url) { "git://example.com/foo.git" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to eq(GitDownloadStrategy) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-21 18:42:25 +09:00
										 |  |  |     context "when given SSH Git URL" do | 
					
						
							|  |  |  |       let(:url) { "ssh://git@example.com/foo.git" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to eq(GitDownloadStrategy) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     context "when given a GitHub Git URL" do | 
					
						
							|  |  |  |       let(:url) { "https://github.com/homebrew/brew.git" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it { is_expected.to eq(GitHubGitDownloadStrategy) } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "defaults to curl" do | 
					
						
							|  |  |  |       expect(strategy_detector).to eq(CurlDownloadStrategy) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "raises an error when passed an unrecognized strategy" do | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       expect do | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |         described_class.detect("foo", Class.new) | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |       end.to raise_error(TypeError) | 
					
						
							| 
									
										
										
										
											2021-01-31 14:50:29 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |