2019-04-19 15:38:03 +09:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								# frozen_string_literal: true
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								require "dependency_collector"
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								RSpec.describe DependencyCollector do
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  alias_matcher :be_a_build_requirement, :be_build
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2021-01-31 13:14:23 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  subject(:collector) { described_class.new }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  describe "#add" do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    resource = Resource.new
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-04 11:51:06 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    context "when xz, unzip, and bzip2 are not available" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "creates a resource dependency from a '.xz' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.xz")
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-21 13:44:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("xz")
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-19 06:06:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to eq(Dependency.new("xz", [:build, :test, :implicit]))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "creates a resource dependency from a '.zip' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.zip")
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-04 11:51:06 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("unzip")
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-19 06:06:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to eq(Dependency.new("unzip", [:build, :test, :implicit]))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "creates a resource dependency from a '.bz2' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.tar.bz2")
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-21 13:44:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("bzip2")
							 | 
						
					
						
							
								
									
										
										
										
											2023-06-19 06:06:15 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to eq(Dependency.new("bzip2", [:build, :test, :implicit]))
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    context "when xz, zip, and bzip2 are available" do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "does not create a resource dependency from a '.xz' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.xz")
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-21 13:44:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("xz").and_return(Pathname.new("foo"))
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-01 00:01:13 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to be_nil
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "does not create a resource dependency from a '.zip' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.zip")
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-04 11:51:06 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("unzip").and_return(Pathname.new("foo"))
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-01 00:01:13 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to be_nil
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      it "does not create a resource dependency from a '.bz2' URL" do
							 | 
						
					
						
							
								
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        resource.url("https://brew.sh/foo.tar.bz2")
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-21 13:44:51 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        allow_any_instance_of(Object).to receive(:which).with("bzip2").and_return(Pathname.new("foo"))
							 | 
						
					
						
							
								
									
										
										
										
											2022-03-01 00:01:13 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        expect(collector.add(resource)).to be_nil
							 | 
						
					
						
							
								
									
										
										
										
											2018-02-20 21:33:38 +00:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 |