spec/dir_spec.rb in vfs-0.3.15 vs spec/dir_spec.rb in vfs-0.4.0
- old
+ new
@@ -1,21 +1,21 @@
require 'spec_helper'
describe 'Dir' do
- with_test_fs
+ with_test_dir
before do
- @path = test_fs['a/b/c']
+ @path = test_dir['a/b/c']
end
describe 'existence' do
it "should check only dirs" do
@path.should_not exist
@path.file.create
@path.should be_file
@path.dir.should_not exist
- @path.dir.create!
+ @path.dir.create
@path.should be_dir
@path.dir.should exist
end
end
@@ -25,11 +25,10 @@
end
describe 'create' do
it 'should be chainable' do
@path.dir.create.should == @path
- @path.dir.create!.should == @path
end
it 'should create parent dirs if not exists' do
@path.parent.should_not exist
@path.dir.create
@@ -39,53 +38,54 @@
it 'should silently exit if dir already exist' do
@path.dir.create
@path.dir.create
end
- it 'should override existing file if override specified' do
+ it 'should override existing file' do
@path.file.create
@path.should be_file
- -> {@path.dir.create}.should raise_error(Vfs::Error, /exist/)
- @path.dir.create!
+ @path.dir.create
@path.should be_dir
end
- it 'should override existing dir if override specified' do
- @path.dir.create
- @path.should be_dir
- @path.dir.create!
- @path.should be_dir
+ it 'should not override existing dir with content' do
+ dir = @path.dir
+ dir.create
+ file = dir.file :file
+ file.create
+ file.should exist
+
+ dir.create
+ file.should exist
end
end
describe 'destroying' do
- it "should raise error if it's trying to destroy a file (unless force specified)" do
+ it "should destroy a file" do
@path.file.create
- -> {@path.dir.destroy}.should raise_error(Vfs::Error, /can't destroy File/)
- @path.dir.destroy!
+ @path.dir.destroy
@path.entry.should_not exist
end
it "shouldn't raise if dir not exist" do
@path.dir.destroy
end
it 'should destroy recursivelly' do
dir = @path.dir
dir.create
- dir.file('file').write 'something'
- dir.dir('dir').create.tap do |dir|
- dir.file('file2').write 'something2'
+ dir.file(:file).write 'something'
+ dir.dir(:dir).create.tap do |dir|
+ dir.file(:file2).write 'something2'
end
dir.destroy
dir.should_not exist
end
it 'should be chainable' do
@path.dir.destroy.should == @path
- @path.dir.destroy!.should == @path
end
end
describe 'entries, files, dirs' do
before do
@@ -95,16 +95,20 @@
end
it 'entries' do
-> {@path['non_existing'].entries}.should raise_error(Vfs::Error, /not exist/)
@path['non_existing'].entries(bang: false).should == []
- @path.entries.to_set.should be_eql([@path.dir('dir'), @path.file('file')].to_set)
+ @path.entries.to_set.should be_eql([@path.entry('dir'), @path.entry('file')].to_set)
list = []
@path.entries{|e| list << e}
- list.to_set.should be_eql([@path.dir('dir'), @path.file('file')].to_set)
+ list.to_set.should be_eql([@path.entry('dir'), @path.entry('file')].to_set)
end
+ it 'entries with type' do
+ @path.entries(type: true).to_set.should be_eql([@path.dir('dir'), @path.file('file')].to_set)
+ end
+
it "glob search support" do
@path.dir('dir_a').create
@path.file('file_a').create
@path.dir('dir_b').create
@path.entries('*_a').collect(&:name).sort.should == %w(dir_a file_a)
@@ -149,36 +153,32 @@
it 'should not copy to itself' do
-> {@from.copy_to @from}.should raise_error(Vfs::Error, /itself/)
end
shared_examples_for 'copy_to behavior' do
- it 'should not copy to file (and overwrite if forced)' do
- -> {@from.copy_to @to.file}.should raise_error(/can't copy Dir to File/)
-
- @from.copy_to! @to.file
+ it 'should copy to file and overwrite it' do
+ @from.copy_to @to.file
@to['file'].read.should == 'something'
end
- it 'should not override files (and override if forced)' do
+ it 'should override files' do
@from.copy_to @to
- -> {@from.copy_to @to}.should raise_error(/already exist/)
- @from['dir/file2'].write! 'another'
- @from.copy_to! @to
+ @from['dir/file2'].write 'another'
+ @from.copy_to @to
@to['dir/file2'].read.should == 'another'
end
- it 'should copy to UniversalEntry (and overwrite if forced)' do
+ it 'should copy to UniversalEntry (and overwrite)' do
@from.copy_to @to.entry
- -> {@from.copy_to @to.entry}.should raise_error(/already exist/)
- @from.copy_to! @to.entry
+ @from.copy_to @to.entry
@to['file'].read.should == 'something'
end
it "shouldn't delete existing content of directory" do
- @to.dir.create!
+ @to.dir.create
@to.file('existing_file').write 'existing_content'
@to.dir('existing_dir').create
@to.file('dir/existing_file2').write 'existing_content2'
@from.copy_to @to
@@ -191,59 +191,59 @@
@to.file('dir/existing_file2').read.should == 'existing_content2'
end
it 'should be chainable' do
@from.copy_to(@to).should == @to
- @from.copy_to!(@to).should == @to
end
it "should override without deleting other files" do
@from.copy_to(@to).should == @to
@to.file('other_file').write 'other'
- @from.copy_to!(@to).should == @to
+ @from.copy_to(@to).should == @to
@to.file('other_file').read.should == 'other'
end
+
+ it "should raise error if try to copy file as dir" do
+ dir = @from.dir 'file'
+ dir.file?.should be_true
+ -> {dir.copy_to @to}.should raise_error(Vfs::Error)
+ end
end
describe 'general copy' do
it_should_behave_like 'copy_to behavior'
before do
# prevenging usage of :efficient_dir_copy
# Vfs::Dir.dont_use_efficient_dir_copy = true
- @to = test_fs['to']
+ @to = test_dir['to']
end
# after do
# Vfs::Dir.dont_use_efficient_dir_copy = false
# end
end
# describe 'effective copy' do
# it_should_behave_like 'copy_to behavior'
#
# before do
- # @to = test_fs['to']
+ # @to = test_dir['to']
# end
# end
end
describe 'moving' do
it 'move_to' do
from, to = @path.file('from'), @path.file('to')
- from.should_receive(:copy_to).with(to, {})
- from.should_receive(:destroy).with({})
+ from.should_receive(:copy_to).with(to)
+ from.should_receive(:destroy).with()
from.move_to to
-
- from.should_receive(:move_to).with(to, override: true)
- from.move_to! to
end
it 'should be chainable' do
from, to = @path.dir('from').create, @path.dir('to')
from.move_to(to).should == to
- from.create
- from.move_to!(to).should == to
end
end
end
\ No newline at end of file