Homebrew::EnvConfig: add tests.
This commit is contained in:
		
							parent
							
								
									ad75e40ce7
								
							
						
					
					
						commit
						33816131a8
					
				@ -30,6 +30,7 @@ RSpec/FilePath:
 | 
			
		||||
    - 'checksum_verification_spec.rb'
 | 
			
		||||
    - 'cxxstdlib_spec.rb'
 | 
			
		||||
    - 'diagnostic_checks_spec.rb'
 | 
			
		||||
    - 'env_config_spec.rb'
 | 
			
		||||
    - 'missing_formula_spec.rb'
 | 
			
		||||
    - 'os/linux/diagnostic_spec.rb'
 | 
			
		||||
    - 'os/mac/diagnostic_spec.rb'
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										66
									
								
								Library/Homebrew/test/env_config_spec.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								Library/Homebrew/test/env_config_spec.rb
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,66 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
require "diagnostic"
 | 
			
		||||
 | 
			
		||||
describe Homebrew::EnvConfig do
 | 
			
		||||
  subject(:env_config) { described_class }
 | 
			
		||||
 | 
			
		||||
  describe ".env_method_name" do
 | 
			
		||||
    it "generates method names" do
 | 
			
		||||
      expect(env_config.env_method_name("HOMEBREW_FOO", {})).to eql("foo")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "generates boolean method names" do
 | 
			
		||||
      expect(env_config.env_method_name("HOMEBREW_BAR", boolean: true)).to eql("bar?")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe ".artifact_domain" do
 | 
			
		||||
    it "returns value if set" do
 | 
			
		||||
      ENV["HOMEBREW_ARTIFACT_DOMAIN"] = "https://brew.sh"
 | 
			
		||||
      expect(env_config.artifact_domain).to eql("https://brew.sh")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "returns nil if empty" do
 | 
			
		||||
      ENV["HOMEBREW_ARTIFACT_DOMAIN"] = ""
 | 
			
		||||
      expect(env_config.artifact_domain).to be_nil
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe ".auto_update_secs" do
 | 
			
		||||
    it "returns value if set" do
 | 
			
		||||
      ENV["HOMEBREW_AUTO_UPDATE_SECS"] = "360"
 | 
			
		||||
      expect(env_config.auto_update_secs).to eql("360")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "returns default if unset" do
 | 
			
		||||
      ENV["HOMEBREW_AUTO_UPDATE_SECS"] = nil
 | 
			
		||||
      expect(env_config.auto_update_secs).to eql("300")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe ".bat?" do
 | 
			
		||||
    it "returns true if set" do
 | 
			
		||||
      ENV["HOMEBREW_BAT"] = "1"
 | 
			
		||||
      expect(env_config.bat?).to be(true)
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "returns false if unset" do
 | 
			
		||||
      ENV["HOMEBREW_BAT"] = nil
 | 
			
		||||
      expect(env_config.bat?).to be(false)
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  describe ".make_jobs" do
 | 
			
		||||
    it "returns value if positive" do
 | 
			
		||||
      ENV["HOMEBREW_MAKE_JOBS"] = "4"
 | 
			
		||||
      expect(env_config.make_jobs).to eql("4")
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    it "returns default if negative" do
 | 
			
		||||
      ENV["HOMEBREW_MAKE_JOBS"] = "-1"
 | 
			
		||||
      expect(Hardware::CPU).to receive(:cores).and_return(16)
 | 
			
		||||
      expect(env_config.make_jobs).to eql("16")
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user