aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/test/support/fake_dirs.rb
blob: ea7acc68563f4a6a1c668e02adac35c721d6d15f (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
# wire in a set of fake link dirs per-test
module FakeDirHooks
  DIRS = [:appdir, :qlplugindir, :binarydir].freeze

  def before_setup
    super

    @canned_dirs = {}

    DIRS.each do |dir_name|
      dir = HOMEBREW_PREFIX.join("#{dir_name}-#{Time.now.to_i}-#{rand(1024)}")
      dir.mkpath
      Hbc.send("#{dir_name}=", dir)
      @canned_dirs[:dir_name] = dir
    end
  end

  def after_teardown
    super

    @canned_dirs.each_value do |dir|
      dir.rmtree if dir.exist?
    end
  end
end

module MiniTest
  class Spec
    include FakeDirHooks
  end
end