2016-08-18 22:11:42 +03:00
|
|
|
require "pathname"
|
|
|
|
require "rspec/its"
|
|
|
|
require "rspec/wait"
|
|
|
|
|
2016-08-21 07:51:25 +02:00
|
|
|
if ENV["HOMEBREW_TESTS_COVERAGE"]
|
|
|
|
require "simplecov"
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
project_root = Pathname.new(File.expand_path("../..", __FILE__))
|
|
|
|
|
|
|
|
# add Homebrew to load path
|
2016-09-20 15:11:33 +02:00
|
|
|
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
|
2016-08-18 22:11:42 +03:00
|
|
|
|
|
|
|
require "global"
|
|
|
|
|
|
|
|
# add Homebrew-Cask to load path
|
|
|
|
$LOAD_PATH.push(project_root.join("lib").to_s)
|
|
|
|
|
|
|
|
# force some environment variables
|
|
|
|
ENV["HOMEBREW_NO_EMOJI"] = "1"
|
|
|
|
ENV["HOMEBREW_CASK_OPTS"] = nil
|
|
|
|
|
2016-08-21 04:48:35 +02:00
|
|
|
require "test/helper/shutup"
|
|
|
|
|
2016-08-18 22:11:42 +03:00
|
|
|
Dir["#{project_root}/spec/support/*.rb"].each(&method(:require))
|
|
|
|
|
|
|
|
# from Homebrew. Provides expects method.
|
|
|
|
require "mocha/api"
|
|
|
|
|
|
|
|
require "hbc"
|
|
|
|
|
|
|
|
class Hbc::TestCask < Hbc::Cask; end
|
|
|
|
|
|
|
|
TEST_TMPDIR = Dir.mktmpdir("homebrew_cask_tests")
|
|
|
|
at_exit do
|
|
|
|
FileUtils.remove_entry(TEST_TMPDIR)
|
|
|
|
end
|
|
|
|
|
|
|
|
# override Homebrew locations
|
|
|
|
Hbc.homebrew_prefix = Pathname.new(TEST_TMPDIR).join("prefix")
|
|
|
|
Hbc.homebrew_repository = Hbc.homebrew_prefix
|
|
|
|
Hbc.binarydir = Hbc.homebrew_prefix.join("binarydir", "bin")
|
|
|
|
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("appdir")
|
|
|
|
|
|
|
|
# Override Tap::TAP_DIRECTORY to use our test Tap directory.
|
|
|
|
class Tap
|
|
|
|
send(:remove_const, :TAP_DIRECTORY)
|
|
|
|
TAP_DIRECTORY = Hbc.homebrew_repository.join("Library", "Taps")
|
|
|
|
end
|
|
|
|
|
|
|
|
Hbc.default_tap = Tap.fetch("caskroom", "speccasks")
|
|
|
|
Hbc.default_tap.path.dirname.mkpath
|
|
|
|
|
|
|
|
# also jack in some test Casks
|
|
|
|
FileUtils.ln_s project_root.join("spec", "support"), Tap::TAP_DIRECTORY.join("caskroom", "homebrew-speccasks")
|
|
|
|
|
|
|
|
# create cache directory
|
|
|
|
Hbc.homebrew_cache = Pathname.new(TEST_TMPDIR).join("cache")
|
|
|
|
Hbc.cache.mkpath
|
|
|
|
|
|
|
|
# our own testy caskroom
|
|
|
|
Hbc.caskroom = Hbc.homebrew_prefix.join("TestCaskroom")
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
config.order = :random
|
2016-08-21 04:48:35 +02:00
|
|
|
config.include(Test::Helper::Shutup)
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|