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
|
########################################################################
# test_constructor.rb
#
# Various tests for the Pathname.new method.
########################################################################
require 'pathname2'
require 'test-unit'
class TC_Pathname_Constructor < Test::Unit::TestCase
def setup
@abs_path = "C:/Users"
@rel_path = "Users"
@url_path = "file:///C:/Documents%20and%20Settings"
end
test "constructor handles absolute paths properly" do
assert_nothing_raised{ Pathname.new(@abs_path) }
assert_equal("C:\\Users", Pathname.new(@abs_path).to_s)
end
test "constructor handles relative paths properly" do
assert_nothing_raised{ Pathname.new(@rel_path) }
assert_equal("Users", Pathname.new(@rel_path).to_s)
end
test "constructor handles file URL's properly" do
assert_nothing_raised{ Pathname.new(@url_path) }
assert_equal("C:\\Documents and Settings", Pathname.new(@url_path).to_s)
end
test "constructor returns a Pathname object" do
assert_kind_of(Pathname, Pathname.new(@abs_path))
end
test "constructor handles frozen arguments without issue" do
assert_nothing_raised{ Pathname.new(@abs_path.freeze) }
end
test "constructor raises an error if string argument is too long" do
assert_raise(ArgumentError){ Pathname.new("foo" * 1000) }
end
def teardown
@url_path = nil
@rel_path = nil
@abs_path = nil
end
end
|