test/tc_find.rb in file-find-0.1.1 vs test/tc_find.rb in file-find-0.2.0
- old
+ new
@@ -10,21 +10,31 @@
class TC_File_Find < Test::Unit::TestCase
def setup
@file1 = 'test1.rb'
@file2 = 'test1.txt'
+ @file3 = 'foo.txt'
@link1 = 'link1'
+ @dir1 = 'dir1'
+ @dir2 = 'dir2'
File.open(@file1, 'w'){}
File.open(@file2, 'w'){}
+ File.open(@file3, 'w'){}
File.symlink(@file1, @link1)
+ Dir.mkdir(@dir1) unless File.exists?(@dir1)
+ Dir.mkdir(@dir2) unless File.exists?(@dir2)
+
+ File.open(File.join(@dir1, 'bar.txt'), 'w'){}
+ File.open(File.join(@dir2, 'baz.txt'), 'w'){}
+
@rule1 = File::Find.new(:name => '*.rb')
end
def test_version
- assert_equal('0.1.1', File::Find::VERSION)
+ assert_equal('0.2.0', File::Find::VERSION)
end
def test_path
assert_respond_to(@rule1, :path)
assert_respond_to(@rule1, :path=)
@@ -101,10 +111,35 @@
assert_respond_to(@rule1, :name)
assert_respond_to(@rule1, :name=)
assert_equal('*.rb', @rule1.name)
end
+ def test_perm_basic
+ assert_respond_to(@rule1, :perm)
+ assert_respond_to(@rule1, :perm=)
+ assert_nil(@rule1.perm)
+ end
+
+ def test_perm
+ File.chmod(0666, @file1)
+ File.chmod(0644, @file2)
+ results = File::Find.new(:name => "test1*", :perm => 666).find
+ assert_equal(true, results.length == 1)
+ assert_equal('test1.rb', File.basename(results.first))
+ end
+
+ def test_prune_basic
+ assert_respond_to(@rule1, :prune)
+ assert_respond_to(@rule1, :prune=)
+ assert_nil(@rule1.prune)
+ end
+
+ def test_prune
+ rule = File::Find.new(:name => "*.txt", :prune => 'foo')
+ assert_equal('test1.txt', File.basename(rule.find.first))
+ end
+
def test_size_basic
assert_respond_to(@rule1, :size)
assert_respond_to(@rule1, :size=)
assert_nil(@rule1.size)
end
@@ -120,8 +155,11 @@
end
def teardown
FileUtils.rm_rf(@file1)
FileUtils.rm_rf(@file2)
+ FileUtils.rm_rf(@file3)
FileUtils.rm_rf(@link1)
+ FileUtils.rm_rf(@dir1)
+ FileUtils.rm_rf(@dir2)
end
end