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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
# encoding: utf-8
require 'core_ext/file'
describe 'File::absolute_path?' do
context 'posix' do
before(:each) do
stub_const("File::ALT_SEPARATOR", nil)
stub_const("File::ABSOLUTE_PATH_PATTERN", File::POSIX_ABSOLUTE_PATH_PATTERN)
end
context 'when given an absolute path' do
%w(
/foo/bar
/C/Windows/system32/
).each do |path|
context "(#{path})" do
context 'the return value' do
subject { File::absolute_path?(path) }
it { should be_true }
end
end
end
end
context 'when given a relative path' do
%w(
C:/foo/bar
\\foo\\bar
C:\\foo\\bar
foo/bar
foo
./foo/bar
../foo/bar
C:foo/bar
).each do |path|
context "(#{path})" do
context 'the return value' do
subject { File::absolute_path?(path) }
it { should be_false }
end
end
end
end
end
context 'windows' do
before(:each) do
stub_const("File::ALT_SEPARATOR", '\\')
stub_const("File::ABSOLUTE_PATH_PATTERN", File::WINDOWS_ABSOLUTE_PATH_PATTERN)
end
context 'when given an absolute path' do
%w(
/foo/bar
C:/foo/bar
\\foo\\bar
C:\\foo\\bar
/C/Windows/system32/
).each do |path|
context "(#{path})" do
context 'the return value' do
subject { File::absolute_path?(path) }
it { should be_true }
end
end
end
end
context 'when given a relative path' do
%w(
foo/bar
foo
./foo/bar
../foo/bar
C:foo/bar
).each do |path|
context "(#{path})" do
context 'the return value' do
subject { File::absolute_path?(path) }
it { should be_false }
end
end
end
end
end
end
|