Merge pull request #1328 from jawshooah/cask/fix-tests

Unset HOMEBREW_DEVELOPER in cask tests likely to raise deprecation errors
This commit is contained in:
Josh Hagins 2016-10-19 14:08:27 -04:00 committed by GitHub
commit de5cadc447
8 changed files with 39 additions and 40 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

View File

@ -1,6 +1,7 @@
require 'test_helper'
describe "Casks" do
with_environment "HOMEBREW_DEVELOPER" => nil do
Hbc.all.reject {|c| c.is_a?(Hbc::TestCask) }.each do |cask|
describe "#{cask}" do
it "passes audit" do
@ -11,4 +12,5 @@ describe "Casks" do
end
end
end
end
end

View File

@ -69,6 +69,7 @@ describe Hbc::DSL do
end
it "may use deprecated DSL version hash syntax" do
with_environment "HOMEBREW_DEVELOPER" => nil do
test_cask = Hbc.load("with-dsl-version")
test_cask.token.must_equal "with-dsl-version"
test_cask.url.to_s.must_equal "http://example.com/TestCask.dmg"
@ -76,6 +77,7 @@ describe Hbc::DSL do
test_cask.version.to_s.must_equal "1.2.3"
end
end
end
describe "name stanza" do
it "lets you set the full name via a name stanza" do

View File

@ -17,7 +17,9 @@ 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"
include Test::Helper::Env
include Test::Helper::Shutup
def sudo(*args)

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)