test/path_test.rb in iostreams-0.20.3 vs test/path_test.rb in iostreams-1.0.0.beta
- old
+ new
@@ -1,52 +1,54 @@
require_relative 'test_helper'
module IOStreams
class PathTest < Minitest::Test
- describe IOStreams do
- describe '.root' do
- it 'return default path' do
- path = ::File.expand_path(::File.join(__dir__, '../tmp/default'))
- assert_equal path, IOStreams.root.to_s
+ describe IOStreams::Path do
+ describe '.join' do
+ let(:path) { IOStreams::Path.new('some_path') }
+
+ it 'returns self when no elements' do
+ assert_equal path.object_id, path.join.object_id
end
- it 'return downloads path' do
- path = ::File.expand_path(::File.join(__dir__, '../tmp/downloads'))
- assert_equal path, IOStreams.root(:downloads).to_s
+ it 'adds element to path' do
+ assert_equal ::File.join('some_path', 'test'), path.join('test').to_s
end
- end
- describe '.path' do
- it 'returns path' do
- assert_equal IOStreams.root.to_s, IOStreams.join.to_s
+ it 'adds paths to root' do
+ assert_equal ::File.join('some_path', 'test', 'second', 'third'), path.join('test', 'second', 'third').to_s
end
- it 'adds path to root' do
- assert_equal ::File.join(IOStreams.root.to_s, 'test'), IOStreams.join('test').to_s
+ it 'returns path and filename' do
+ assert_equal ::File.join('some_path', 'file.xls'), path.join('file.xls').to_s
end
- it 'adds paths to root' do
- assert_equal ::File.join(IOStreams.root.to_s, 'test', 'second', 'third'), IOStreams.join('test', 'second', 'third').to_s
+ it 'adds elements to path' do
+ assert_equal ::File.join('some_path', 'test', 'second', 'third', 'file.xls'), path.join('test', 'second', 'third', 'file.xls').to_s
end
- it 'returns path and filename' do
- path = ::File.join(IOStreams.root.to_s, 'file.xls')
- assert_equal path, IOStreams.join('file.xls').to_s
+ it 'return path as sent in when full path' do
+ assert_equal ::File.join('some_path', 'test', 'second', 'third', 'file.xls'), path.join('some_path', 'test', 'second', 'third', 'file.xls').to_s
end
+ end
- it 'adds path to root and filename' do
- path = ::File.join(IOStreams.root.to_s, 'test', 'file.xls')
- assert_equal path, IOStreams.join('test', 'file.xls').to_s
+ describe '#absolute?' do
+ it 'true on absolute' do
+ assert_equal true, IOStreams::Path.new('/a/b/c/d').absolute?
end
- it 'adds paths to root' do
- path = ::File.join(IOStreams.root.to_s, 'test', 'second', 'third', 'file.xls')
- assert_equal path, IOStreams.join('test', 'second', 'third', 'file.xls').to_s
+ it 'false when not absolute' do
+ assert_equal false, IOStreams::Path.new('a/b/c/d').absolute?
end
+ end
- it 'return path as sent in when full path' do
- path = ::File.join(IOStreams.root.to_s, 'file.xls')
- assert_equal path, IOStreams.join(path).to_s
+ describe '#relatve?' do
+ it 'true on relative' do
+ assert_equal true, IOStreams::Path.new('a/b/c/d').relative?
+ end
+
+ it 'false on absolute' do
+ assert_equal false, IOStreams::Path.new('/a/b/c/d').relative?
end
end
end
end
end