Skip to content
Snippets Groups Projects
Commit e8b6aa4e authored by Josh Hagins's avatar Josh Hagins
Browse files

cask/spec: replace with_env_var with with_environment

parent fba00f2b
No related branches found
Tags 1.1.5
No related merge requests found
......@@ -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
......
......@@ -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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment