cask/spec: replace with_env_var with with_environment

This commit is contained in:
Josh Hagins 2016-10-19 12:34:03 -04:00
parent fba00f2bbf
commit e8b6aa4ed1
3 changed files with 4 additions and 18 deletions

View File

@ -41,14 +41,14 @@ describe Hbc::CLI do
end
it "respects the env variable when choosing what appdir to create" do
EnvHelper.with_env_var("HOMEBREW_CASK_OPTS", "--appdir=/custom/appdir") do
with_environment "HOMEBREW_CASK_OPTS" => "--appdir=/custom/appdir" do
expect(Hbc).to receive(:appdir=).with(Pathname("/custom/appdir"))
described_class.process("noop")
end
end
it "respects the env variable when choosing a non-default Caskroom location" do
EnvHelper.with_env_var "HOMEBREW_CASK_OPTS", "--caskroom=/custom/caskdir" do
with_environment "HOMEBREW_CASK_OPTS" => "--caskroom=/custom/caskdir" do
expect(Hbc).to receive(:caskroom=).with(Pathname("/custom/caskdir"))
described_class.process("noop")
end

View File

@ -16,6 +16,7 @@ require "global"
# add Homebrew-Cask to load path
$LOAD_PATH.push(project_root.join("lib").to_s)
require "test/helper/env"
require "test/helper/shutup"
Dir["#{project_root}/spec/support/*.rb"].each(&method(:require))
@ -61,5 +62,6 @@ Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom")
RSpec.configure do |config|
config.order = :random
config.include(Test::Helper::Env)
config.include(Test::Helper::Shutup)
end

View File

@ -1,16 +0,0 @@
module EnvHelper
class << self
def with_env_var(key, val)
was_defined = ENV.key? "key"
old_value = ENV["key"]
ENV[key] = val
yield
ensure
if was_defined
ENV[key] = old_value
else
ENV.delete(key)
end
end
end
end