aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorJack Nagel2013-04-16 01:43:26 -0500
committerJack Nagel2013-04-16 01:58:11 -0500
commit3a0726406bf3482cdfb5d992ee29b1aefde363ea (patch)
treeb294568c541f55ed476c274b63924cdebf6cfa91 /Library/Homebrew/test
parentd600d6c0bebaf56ffb47ff7e9e1ac644d36c7a7d (diff)
downloadbrew-3a0726406bf3482cdfb5d992ee29b1aefde363ea.tar.bz2
Add tests for FormulaPin and simplify implementation
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/test_formula.rb21
-rw-r--r--Library/Homebrew/test/test_formula_pin.rb48
2 files changed, 59 insertions, 10 deletions
diff --git a/Library/Homebrew/test/test_formula.rb b/Library/Homebrew/test/test_formula.rb
index 22fb2f238..bd900bf71 100644
--- a/Library/Homebrew/test/test_formula.rb
+++ b/Library/Homebrew/test/test_formula.rb
@@ -106,19 +106,19 @@ class FormulaTests < Test::Unit::TestCase
assert_instance_of HeadSoftwareSpec, f.head
end
- def test_formula_funcs
- foobar = 'foo-bar'
- path = Formula.path(foobar)
-
- assert_match Regexp.new("^#{HOMEBREW_PREFIX}/Library/Formula"),
- path.to_s
+ def test_path
+ name = 'foo-bar'
+ assert_equal Pathname.new("#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb"), Formula.path(name)
+ end
- path = HOMEBREW_PREFIX+"Library/Formula/#{foobar}.rb"
+ def test_factory
+ name = 'foo-bar'
+ path = HOMEBREW_PREFIX+"Library/Formula/#{name}.rb"
path.dirname.mkpath
File.open(path, 'w') do |f|
f << %{
require 'formula'
- class #{Formula.class_s(foobar)} < Formula
+ class #{Formula.class_s(name)} < Formula
url 'foo-1.0'
def initialize(*args)
@homepage = 'http://example.com/'
@@ -127,7 +127,8 @@ class FormulaTests < Test::Unit::TestCase
end
}
end
-
- assert_not_nil Formula.factory(foobar)
+ assert_kind_of Formula, Formula.factory(name)
+ ensure
+ path.unlink
end
end
diff --git a/Library/Homebrew/test/test_formula_pin.rb b/Library/Homebrew/test/test_formula_pin.rb
new file mode 100644
index 000000000..938fd51f8
--- /dev/null
+++ b/Library/Homebrew/test/test_formula_pin.rb
@@ -0,0 +1,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