spec/base_spec.rb in fs-0.1.2 vs spec/base_spec.rb in fs-0.2.0

- old
+ new

@@ -135,22 +135,16 @@ FS.touch('foo/file.rb') FS.makedir('foo/dir.txt') FS.makedir('foo/dir.rb') FS.list('foo', '*.txt').should eql(['dir.txt', 'file.txt']) end - end - describe '::find' do - it 'returns an empty list if there are no files' do - FS.find('.').should be_empty - end - - it 'finds files in all subdirs' do + it 'lists files in all subdirs' do FS.makedirs('one/two/three') FS.touch('one/file.one') FS.touch('one/two/three/file.three') - FS.find.should eql([ + FS.list('.', '**/*').should eql([ 'one', 'one/file.one', 'one/two', 'one/two/three', 'one/two/three/file.three' @@ -159,17 +153,43 @@ it 'globs files in all subdirs' do FS.makedirs('one/two/three') FS.touch('one/file.one') FS.touch('one/two/three/file.three') - FS.find('.', 'file.*').should eql([ + FS.list('.', '**/file.*').should eql([ 'one/file.one', 'one/two/three/file.three' ]) end end + describe '::list_dirs' do + it 'lists dirs only' do + FS.touch('bar.file') + FS.makedir('bar.dir') + FS.touch('foo.file') + FS.makedir('foo.dir') + FS.list_dirs.should eql([ + 'bar.dir', + 'foo.dir' + ]) + end + end + + describe '::list_files' do + it 'lists files only' do + FS.touch('bar.file') + FS.makedir('bar.dir') + FS.touch('foo.file') + FS.makedir('foo.dir') + FS.list_files.should eql([ + 'bar.file', + 'foo.file' + ]) + end + end + describe '::move' do it 'renames a file' do FS.touch('foo.txt') FS.move('foo.txt', 'bar.txt') FS.list.should eql(['bar.txt']) @@ -325,11 +345,11 @@ describe '::tree' do before(:each) do FS.touch('a.file') FS.makedir('baz') FS.touch('baz/b.file') - FS.mkdir('baz/bar') + FS.makedir('baz/bar') FS.touch('baz/bar/c.file') FS.touch('baz/d.file') FS.makedir('foo') FS.touch('foo/e.file') end @@ -404,12 +424,12 @@ FS.empty?('empty.file').should be_true FS.empty?('content.file').should be_false end it 'returns if a dir is empty' do - FS.mkdir('empty.dir') - FS.mkdir('content.dir') + FS.makedir('empty.dir') + FS.makedir('content.dir') FS.touch('content.dir/some.file') FS.empty?('empty.dir').should be_true FS.empty?('content.dir').should be_false end end @@ -427,12 +447,52 @@ here = File.expand_path('.') FS.expand_path('.').should eql(here) FS.expand_path('foo').should eql(File.join(here, 'foo')) FS.expand_path('foo/bar').should eql(File.join(here, 'foo', 'bar')) end + + it 'uses a base dir to expand the path' do + here = File.expand_path('.') + FS.expand_path('foo', nil).should eql(File.join(here, 'foo')) + FS.expand_path('foo', here).should eql(File.join(here, 'foo')) + FS.expand_path('foo', '/').should eql('/foo') + FS.expand_path('foo', '/bar').should eql('/bar/foo') + FS.expand_path('foo', '/bar/').should eql('/bar/foo') + end end + describe '::chop_path' do + it 'does nothing for relative paths' do + FS.chop_path('.').should eql('.') + FS.chop_path('./foo').should eql('foo') + FS.chop_path('foo').should eql('foo') + FS.chop_path('foo/bar').should eql('foo/bar') + end + + it 'does not chop for non subdirs' do + FS.chop_path('/').should eql('/') + FS.chop_path('..').should eql(File.expand_path('..')) + FS.chop_path('/foo', '/foo/bar').should eql('/foo') + end + + it 'chop absolute the path' do + here = File.expand_path('.') + FS.chop_path(here).should eql('.') + FS.chop_path(File.join(here, '.')).should eql('.') + FS.chop_path(File.join(here, 'foo')).should eql('foo') + FS.chop_path(File.join(here, 'foo/bar')).should eql('foo/bar') + FS.chop_path('/foo/bar').should eql('/foo/bar') + end + + it 'uses a base dir to chop the path' do + FS.chop_path('.', '.').should eql('.') + FS.chop_path('/', '/').should eql('.') + FS.chop_path('/foo', '/foo').should eql('.') + FS.chop_path('/foo/bar', '/foo').should eql('bar') + end + end + describe '::absolute?' do it 'checks for an absolute path' do FS.absolute?('/').should be_true FS.absolute?('/foo').should be_true FS.absolute?('.').should be_false @@ -518,28 +578,28 @@ describe '::maketempdir' do it 'creates a new dir in the default temp dir' do dir = FS.maketempdir File.exist?(dir).should be_true File.directory?(dir).should be_true - Dir.entries(dir).should eql([".", ".."]) + Dir.entries(dir).should =~ ['.', '..'] Dir.entries(Dir.tmpdir).should include(File.basename(dir)) end it 'creates a new temp dir with the given prefix' do dir = FS.maketempdir('my_dir') dir.should match(/\/my_dir/) File.exist?(dir).should be_true File.directory?(dir).should be_true - Dir.entries(dir).should eql([".", ".."]) + Dir.entries(dir).should =~ ['.', '..'] Dir.entries(Dir.tmpdir).should include(File.basename(dir)) end it 'creates a new temp dir inside of the given dir' do parent_dir = FS.maketempdir('parent_dir') dir = FS.maketempdir(nil, parent_dir) File.exist?(dir).should be_true File.directory?(dir).should be_true - Dir.entries(dir).should eql([".", ".."]) + Dir.entries(dir).should =~ ['.', '..'] Dir.entries(parent_dir).should include(File.basename(dir)) end end describe '::maketempfile' do