tests: automatically restore ENV in teardown
This commit is contained in:
		
							parent
							
								
									6e0f1366b0
								
							
						
					
					
						commit
						116ed3ec80
					
				@ -361,13 +361,10 @@ class FormulaAuditorTests < Homebrew::TestCase
 | 
			
		||||
      end
 | 
			
		||||
    EOS
 | 
			
		||||
 | 
			
		||||
    original_value = ENV["HOMEBREW_NO_GITHUB_API"]
 | 
			
		||||
    ENV["HOMEBREW_NO_GITHUB_API"] = "1"
 | 
			
		||||
 | 
			
		||||
    fa.audit_github_repository
 | 
			
		||||
    assert_equal [], fa.problems
 | 
			
		||||
  ensure
 | 
			
		||||
    ENV["HOMEBREW_NO_GITHUB_API"] = original_value
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_audit_caveats
 | 
			
		||||
 | 
			
		||||
@ -47,8 +47,6 @@ class CommandsTests < Homebrew::TestCase
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_external_commands
 | 
			
		||||
    env = ENV.to_hash
 | 
			
		||||
 | 
			
		||||
    mktmpdir do |dir|
 | 
			
		||||
      %w[brew-t1 brew-t2.rb brew-t3.py].each do |file|
 | 
			
		||||
        path = "#{dir}/#{file}"
 | 
			
		||||
@ -67,8 +65,6 @@ class CommandsTests < Homebrew::TestCase
 | 
			
		||||
        "Executable files with a non Ruby extension shoudn't be included"
 | 
			
		||||
      refute cmds.include?("t4"), "Non-executable files shouldn't be included"
 | 
			
		||||
    end
 | 
			
		||||
  ensure
 | 
			
		||||
    ENV.replace(env)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_internal_command_path
 | 
			
		||||
 | 
			
		||||
@ -6,15 +6,9 @@ require "diagnostic"
 | 
			
		||||
class DiagnosticChecksTest < Homebrew::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @env = ENV.to_hash
 | 
			
		||||
    @checks = Homebrew::Diagnostic::Checks.new
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    ENV.replace(@env)
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_inject_file_list
 | 
			
		||||
    assert_equal "foo:\n",
 | 
			
		||||
      @checks.inject_file_list([], "foo:\n")
 | 
			
		||||
 | 
			
		||||
@ -6,15 +6,9 @@ require "diagnostic"
 | 
			
		||||
class OSMacDiagnosticChecksTest < Homebrew::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @env = ENV.to_hash
 | 
			
		||||
    @checks = Homebrew::Diagnostic::Checks.new
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    ENV.replace(@env)
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_check_for_other_package_managers
 | 
			
		||||
    MacOS.stubs(:macports_or_fink).returns ["fink"]
 | 
			
		||||
    assert_match "You have MacPorts or Fink installed:",
 | 
			
		||||
 | 
			
		||||
@ -37,7 +37,6 @@ class ShellSmokeTest < Homebrew::TestCase
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def prepend_path_shell(shell, path, fragment)
 | 
			
		||||
    original_shell = ENV["SHELL"]
 | 
			
		||||
    ENV["SHELL"] = shell
 | 
			
		||||
 | 
			
		||||
    prepend_message = Utils::Shell.prepend_path_in_shell_profile(path)
 | 
			
		||||
@ -45,8 +44,6 @@ class ShellSmokeTest < Homebrew::TestCase
 | 
			
		||||
      prepend_message.start_with?(fragment),
 | 
			
		||||
      "#{shell}: expected #{prepend_message} to match #{fragment}"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    ENV["SHELL"] = original_shell
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_prepend_path_in_shell_profile
 | 
			
		||||
 | 
			
		||||
@ -16,11 +16,14 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
    def setup
 | 
			
		||||
      super
 | 
			
		||||
 | 
			
		||||
      @__argv = ARGV.dup
 | 
			
		||||
      @__env = copy_env # Call #to_hash to duplicate ENV
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def teardown
 | 
			
		||||
      ARGV.replace(@__argv)
 | 
			
		||||
      restore_env @__env
 | 
			
		||||
 | 
			
		||||
      Tab.clear_cache
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,12 +7,6 @@ class UtilTests < Homebrew::TestCase
 | 
			
		||||
  def setup
 | 
			
		||||
    super
 | 
			
		||||
    @dir = Pathname.new(mktmpdir)
 | 
			
		||||
    @env = ENV.to_hash
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def teardown
 | 
			
		||||
    ENV.replace @env
 | 
			
		||||
    super
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_ofail
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user