aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/spec/spec_helper.rb
blob: 6bb13bdcf14b827a383742d99b0135a0dbf93a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "pathname"
require "rspec/its"
require "rspec/wait"

if ENV["HOMEBREW_TESTS_COVERAGE"]
  require "simplecov"
  SimpleCov.command_name "test:cask:rspec"
end

project_root = Pathname.new(File.expand_path("../..", __FILE__))

# add Homebrew to load path
$LOAD_PATH.unshift(File.expand_path("#{ENV['HOMEBREW_REPOSITORY']}/Library/Homebrew"))

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

require "test/helper/shutup"

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
  config.include(Test::Helper::Shutup)
end