brew/Library/Homebrew/cask/spec/spec_helper.rb
2017-02-10 17:19:19 +01:00

77 lines
2.0 KiB
Ruby

require "pathname"
require "rspec/its"
require "rspec/wait"
if ENV["HOMEBREW_TESTS_COVERAGE"]
require "simplecov"
end
# add Homebrew to load path
$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"))
require "global"
# add Homebrew-Cask to load path
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
require "test/support/helper/shutup"
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "**", "*.rb")).each(&method(:require))
require "hbc"
# create and override default directories
Hbc.appdir = Pathname.new(TEST_TMPDIR).join("Applications").tap(&:mkpath)
Hbc.cache.mkpath
Hbc.caskroom = Hbc.default_caskroom.tap(&:mkpath)
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
end
# 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
RSpec.configure do |config|
config.order = :random
config.include(Test::Helper::Shutup)
config.around(:each) do |example|
begin
@__appdir = Hbc.appdir
@__caskroom = Hbc.caskroom
@__prefpanedir = Hbc.prefpanedir
@__qlplugindir = Hbc.qlplugindir
@__servicedir = Hbc.servicedir
@__argv = ARGV.dup
@__env = ENV.to_hash # dup doesn't work on ENV
example.run
ensure
ARGV.replace(@__argv)
ENV.replace(@__env)
Hbc.appdir = @__appdir
Hbc.caskroom = @__caskroom
Hbc.prefpanedir = @__prefpanedir
Hbc.qlplugindir = @__qlplugindir
Hbc.servicedir = @__servicedir
FileUtils.rm_rf [
Hbc.appdir.children,
Hbc.caskroom.children,
]
end
end
end
module Hbc
class NeverSudoSystemCommand < SystemCommand
def self.run(command, options = {})
super(command, options.merge(sudo: false))
end
end
end