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
|
########################################################################
# test_descend.rb
#
# Test suite for the Pathname#descend method.
########################################################################
require 'pathname2'
require 'test-unit'
class TC_Pathname_Descend < Test::Unit::TestCase
def setup
@path = Pathname.new("C:\\foo\\bar\\baz")
end
test "descend basic functionality" do
assert_respond_to(@path, :descend)
assert_nothing_raised{ @path.descend{} }
end
test "descend works as expected on a standard absolute path" do
array = []
@path.descend{ |e| array << e }
assert_equal('C:', array[0])
assert_equal('C:\foo', array[1])
assert_equal('C:\foo\bar', array[2])
assert_equal('C:\foo\bar\baz', array[3])
end
test "descend works as expected on a UNC path" do
array = []
Pathname.new('//foo/bar/baz').descend{ |e| array << e }
assert_equal("\\\\foo\\bar", array[0])
assert_equal("\\\\foo\\bar\\baz", array[1])
end
test "descend works as expected on a relative path" do
array = []
Pathname.new('foo/bar/baz').descend{ |e| array << e }
assert_equal('foo', array[0])
assert_equal('foo\bar', array[1])
assert_equal('foo\bar\baz', array[2])
end
test "descend does not modify the receiver" do
@path.descend{}
assert_equal('C:\foo\bar\baz', @path)
end
def teardown
@path = nil
end
end
|