aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_formula_pin.rb
blob: 938fd51f815bdae5bf1bc2ddfaa7949fa8a8826a (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
require 'testing_env'
require 'formula_pin'

class FormulaPinTests < Test::Unit::TestCase
  class FormulaDouble
    def name
      "double"
    end

    def rack
      Pathname.new("#{HOMEBREW_CELLAR}/#{name}")
    end
  end

  def setup
    @f   = FormulaDouble.new
    @pin = FormulaPin.new(@f)
    @f.rack.mkpath
  end

  def test_not_pinnable
    assert !@pin.pinnable?
  end

  def test_pinnable_if_kegs_exist
    (@f.rack+'0.1').mkpath
    assert @pin.pinnable?
  end

  def test_pin
    (@f.rack+'0.1').mkpath
    @pin.pin
    assert @pin.pinned?
    assert_equal 1, FormulaPin::PINDIR.children.length
  end

  def test_unpin
    (@f.rack+'0.1').mkpath
    @pin.pin
    @pin.unpin
    assert !@pin.pinned?
    assert_equal 0, FormulaPin::PINDIR.children.length
  end

  def teardown
    @f.rack.rmtree
  end
end