testing_env: extract with_environment to helper module

This commit is contained in:
Josh Hagins 2016-10-19 12:32:48 -04:00
parent b9fe36abdc
commit fba00f2bbf
2 changed files with 17 additions and 10 deletions

View File

@ -0,0 +1,15 @@
module Test
module Helper
module Env
def with_environment(partial_env)
old = ENV.to_hash
ENV.update partial_env
begin
yield
ensure
ENV.replace old
end
end
end
end
end

View File

@ -63,7 +63,9 @@ module Homebrew
end
class TestCase < ::Minitest::Test
require "test/helper/env"
require "test/helper/shutup"
include Test::Helper::Env
include Test::Helper::Shutup
include VersionAssertions
@ -112,16 +114,6 @@ module Homebrew
Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.bundle")
end
def with_environment(partial_env)
old = ENV.to_hash
ENV.update partial_env
begin
yield
ensure
ENV.replace old
end
end
# Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
# when loading from {Formulary} with `ref`.
def stub_formula_loader(formula, ref = formula.full_name)