homebrew-cask/test/test_helper.rb

72 lines
1.7 KiB
Ruby
Raw Normal View History

require 'bundler/setup'
# add cask lib to load path
brew_cask_path = Pathname.new(File.expand_path(__FILE__+'/../../'))
casks_path = brew_cask_path.join('casks')
lib_path = brew_cask_path.join('lib')
$:.push(lib_path)
# add homebrew to load path
homebrew_path = Pathname(`brew --prefix`.chomp)
$:.push(homebrew_path.join('Library', 'Homebrew'))
# require homebrew testing env
require 'test/testing_env'
# making homebrew's cache dir allows us to actually download casks in tests
HOMEBREW_CACHE.mkpath
# must be called after testing_env so at_exit hooks are in proper order
require 'minitest/autorun'
require 'minitest-colorize'
# our baby
require 'cask'
# look for casks in testcasks by default
Cask.default_tap = 'phinze-testcasks'
class TestHelper
# helper for test casks to reference local files easily
def self.local_binary(name)
path = File.expand_path(File.join(File.dirname(__FILE__), 'support', 'binaries', name))
"file://#{path}"
end
2012-11-25 10:13:57 +08:00
def self.test_cask
Cask.load('test-cask')
end
def self.fake_fetcher
Cask::FakeFetcher
end
def self.fake_response_for(*args)
Cask::FakeFetcher.fake_response_for(*args)
end
2013-04-08 01:46:35 +08:00
def self.must_output(test, lambda, expected)
out, err = test.capture_subprocess_io do
lambda.call
end
(out+err).chomp.must_equal expected.gsub(/^ */, '')
end
2012-11-25 10:13:57 +08:00
end
require 'support/fake_fetcher'
2012-11-26 05:05:54 +08:00
require 'support/fake_appdir'
2012-11-25 10:13:57 +08:00
# pretend like we installed the cask tap
project_root = Pathname.new(File.expand_path("#{File.dirname(__FILE__)}/../"))
taps_dest = HOMEBREW_LIBRARY/"Taps"
taps_dest.mkdir
FileUtils.ln_s project_root, taps_dest/"phinze-cask"
# also jack in some test casks
FileUtils.ln_s project_root/'test'/'support', taps_dest/"phinze-testcasks"