require File.join(File.dirname(__FILE__),'../../spec_helper') describe IMW::Schemes::Local::Base do it "should not extend a local file with LocalDirectory" do @file = IMW::Resource.new('foo.txt', :no_modules => true) @file.should_not_receive(:extend).with(IMW::Schemes::Local::LocalDirectory) @file.extend_appropriately! end it "should not extend a local directory with LocalFile" do @dir = IMW::Resource.new(IMWTest::TMP_DIR, :no_modules => true) @dir.should_not_receive(:extend).with(IMW::Schemes::Local::LocalFile) @dir.extend_appropriately! end it "should correctly resolve relative paths" do IMW.open('foobar').dirname.should == IMWTest::TMP_DIR end it "should be able to return its directory as an IMW object" do IMW.open('/path/to/file').dir.path.should == '/path/to' IMW.open('/').dir.path.should == '/' end end describe IMW::Schemes::Local::LocalFile do before do IMWTest::Random.file('original.txt') @file = IMW::Resource.new('original.txt') end it "can delete the file" do @file.rm @file.exist?.should be_false end it "can read a file" do @file.read.size.should > 0 end it "can load the lines of a file" do data = @file.load data.size.should > 0 data.class.should == Array end it "can iterate over the lines of a file" do @file.load do |line| line.class.should == String break end end it "can map the lines of a file" do @file.map do |line| line[0..5] end.class.should == Array end end describe IMW::Schemes::Local::LocalDirectory do before do FileUtils.mkdir_p('dir') FileUtils.mkdir_p('dir/subdir') FileUtils.cd('dir') do IMWTest::Random.file('file1.tsv') IMWTest::Random.file('file2.tsv') FileUtils.cd('subdir') do IMWTest::Random.file('file3.csv') end end @dir = IMW::Resource.new('dir') end it "can delete an empty directory" do FileUtils.mkdir('empty') dir = IMW.open('empty') dir.rmdir dir.exist?.should be_false end it "can recursively delete a directory" do @dir.rm_rf @dir.exist?.should be_false end it "can list its contents" do @dir.contents.size.should == 3 end it "can list its contents recursively" do @dir.all_contents.size.should == 4 end it "can list its contents as IMW::Resource objects" do @dir.resources.map(&:class).uniq.first.should == IMW::Resource end describe 'can package itself to' do ['tar', 'tar.bz2', 'tar.gz', 'zip', 'rar'].each do |extension| it "a #{extension} archive" do @dir.package("package.#{extension}").exist?.should be_true # FIXME should explicitly check paths are correct in archive end end end end