brew/Library/Homebrew/cask/spec/spec_helper.rb

70 lines
1.8 KiB
Ruby
Raw Normal View History

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
# add Homebrew to load path
2016-09-20 15:11:33 +02:00
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew"))
$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_REPOSITORY"]}/Library/Homebrew/test/support/lib"))
2016-08-18 22:11:42 +03:00
require "global"
# add Homebrew-Cask to load path
2016-10-19 23:01:52 +02:00
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
2016-08-18 22:11:42 +03:00
require "test/support/helper/shutup"
2016-08-21 04:48:35 +02:00
2017-02-09 03:49:12 +01:00
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require))
2016-08-18 22:11:42 +03:00
require "hbc"
2016-10-19 23:01:52 +02:00
# create and override default directories
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
2016-08-18 22:11:42 +03:00
Hbc.cache.mkpath
Hbc.caskroom = Hbc.default_caskroom.tap(&:mkpath)
2016-10-19 23:01:52 +02:00
Hbc.default_tap = Tap.fetch("caskroom", "spec").tap do |tap|
# link test casks
FileUtils.mkdir_p tap.path.dirname
FileUtils.ln_s TEST_FIXTURE_DIR.join("cask"), tap.path
2016-10-19 23:01:52 +02:00
end
2016-08-18 22:11:42 +03:00
2017-02-08 12:29:33 +01:00
# pretend that the caskroom/cask Tap is installed
FileUtils.ln_s Pathname.new(ENV["HOMEBREW_LIBRARY"]).join("Taps", "caskroom", "homebrew-cask"), Tap.fetch("caskroom", "cask").path
2017-02-09 04:37:24 +01:00
HOMEBREW_CASK_DIRS = [
:appdir,
:caskroom,
:prefpanedir,
:qlplugindir,
:servicedir,
:binarydir,
].freeze
2016-08-18 22:11:42 +03:00
RSpec.configure do |config|
config.order = :random
2016-08-21 04:48:35 +02:00
config.include(Test::Helper::Shutup)
2017-02-08 13:25:10 +01:00
config.around(:each) do |example|
begin
2017-02-09 04:37:24 +01:00
@__dirs = HOMEBREW_CASK_DIRS.map { |dir|
Pathname.new(TEST_TMPDIR).join(dir.to_s).tap { |path|
path.mkpath
Hbc.public_send("#{dir}=", path)
}
}
2017-02-08 13:25:10 +01:00
@__argv = ARGV.dup
@__env = ENV.to_hash # dup doesn't work on ENV
example.run
ensure
ARGV.replace(@__argv)
ENV.replace(@__env)
2017-02-09 04:37:24 +01:00
FileUtils.rm_rf @__dirs.map(&:children)
2017-02-08 13:25:10 +01:00
end
2017-02-08 08:29:41 +01:00
end
2016-08-18 22:11:42 +03:00
end