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 52 53 54 55 56 57 58 59 60 61 62 63 64
|
########################################################################
# test_facade.rb
#
# Test suite for the various facade methods.
########################################################################
require 'test-unit'
require 'pathname2'
class TC_Pathname_Facade < Test::Unit::TestCase
def setup
@path = Pathname.new("C:/Program Files")
end
test "file facade methods are defined" do
File.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
end
test "dir facade methods are defined" do
Dir.methods(false).each{ |m| assert_respond_to(@path, m.to_sym) }
end
test "fileutils facade methods are defined" do
methods = FileUtils.public_instance_methods
methods -= File.methods(false)
methods -= Dir.methods(false)
# Ruby 1.9.x and 2.0 incorrectly made some of these methods public
methods.delete_if{ |m|
m =~ /stream|^ln|identical\?|mode_to_s|^sh|ruby|safe_ln|split_all/i
}
methods.each{ |method|
assert_respond_to(@path, method.to_sym)
}
end
test "find facade works as expected" do
assert_respond_to(@path, :find)
assert_nothing_raised{ @path.find{} }
Pathname.new(Dir.pwd).find{ |f|
Find.prune if f.match("git")
assert_kind_of(Pathname, f)
}
end
test "custom io methods are defined" do
assert_respond_to(@path, :foreach)
assert_respond_to(@path, :read)
assert_respond_to(@path, :readlines)
assert_respond_to(@path, :sysopen)
end
test "exist? facade works as expected" do
assert_respond_to(@path, :exist?)
assert_nothing_raised{ @path.exist? }
assert_true(Pathname.new("C:\\").exist?)
assert_false(Pathname.new("X:\\foo\\bar\\baz").exist?)
end
def teardown
@path = nil
end
end
|