Skip to content
This repository has been archived by the owner on Dec 24, 2019. It is now read-only.

Commit

Permalink
Merge branch 'byebye_fileutils'
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoskings committed Jan 9, 2011
2 parents 24d5636 + 37d8563 commit 67c5dd5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
6 changes: 3 additions & 3 deletions deps/templates/app.rb
Expand Up @@ -56,13 +56,13 @@ def discover_latest_version
}.map {|entry|
pre = prefix_to_use
target_path = pre / entry
if !target_path.exists? || confirm("Overwrite #{target_path}?") { FileUtils.rm_r target_path }
if !target_path.exists? || confirm("Overwrite #{target_path}?") { target_path.rm }
if archive.is_a? Babushka::DmgResource
log_block("Found #{entry} in the DMG, copying to #{pre}") {
shell "cp -pPR '#{entry}' '#{pre.end_with('/')}'"
entry.copy pre.end_with('/')
}
else
log_block("Found #{entry}, moving to #{pre}") { FileUtils.mv entry, pre.end_with('/') }
log_block("Found #{entry}, moving to #{pre}") { entry.move pre.end_with('/') }
end
end
}
Expand Down
2 changes: 0 additions & 2 deletions lib/babushka/helpers/path_helpers.rb
@@ -1,5 +1,3 @@
require 'fileutils'

module Babushka
module PathHelpers
def in_dir dir, opts = {}, &block
Expand Down
7 changes: 3 additions & 4 deletions lib/fancypath/fancypath.rb
Expand Up @@ -52,7 +52,7 @@ def join(path)

# make file
def touch
FileUtils.touch self.to_s
`touch '#{self}'`
self
end

Expand All @@ -64,7 +64,7 @@ def create_dir
alias_method :create, :create_dir

def copy(dest)
FileUtils.cp(self, dest)
`cp -pPR '#{self}' '#{dest}'`
self
end

Expand All @@ -91,8 +91,7 @@ def readlink
end

def mkdir
require 'fileutils'
FileUtils.mkdir_p self
`mkdir -p '#{self}'`
self
end

Expand Down
5 changes: 2 additions & 3 deletions spec/babushka/path_helpers_spec.rb
Expand Up @@ -2,13 +2,12 @@

class PathTester; extend PathHelpers end

require 'fileutils'
describe "in_dir" do
before do
@tmp_dir = tmp_prefix
FileUtils.mkdir_p @tmp_dir
`mkdir -p '#{@tmp_dir}'`
@tmp_dir_2 = File.join(tmp_prefix, '2')
FileUtils.mkdir_p @tmp_dir_2
`mkdir -p '#{@tmp_dir_2}'`

@original_pwd = Dir.pwd

Expand Down
15 changes: 15 additions & 0 deletions spec/fancypath/fancypath_spec.rb
Expand Up @@ -119,6 +119,21 @@
it('copies the contents') { @file.copy(TMP_DIR/'foo').read.should == @file.read }
end

describe '#copy on a directory' do
before {
@dir.mkdir
(@dir / 'testfile').touch
}
it('returns a Fancypath') { @dir.copy(TMP_DIR/'foo').should be_instance_of(Fancypath) }
it('creates a new dir with a file in it') {
@dir.copy(TMP_DIR/'foo')
(TMP_DIR/'foo').should exist
(TMP_DIR/'foo/testfile').should exist
}
it('keeps the original') { @dir.copy(TMP_DIR/'foo'); @dir.should exist }
it('copies the contents') { @dir.copy(TMP_DIR/'foo'); (TMP_DIR/'foo/testfile').read.should == (@dir/'testfile').read }
end

describe '#set_extension' do
example "file without extension" do
Fancypath('/tmp/foo').set_extension('rb').should == Fancypath('/tmp/foo.rb')
Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Expand Up @@ -15,8 +15,8 @@ def tmp_prefix
"#{'/private' if Base.host.osx?}/tmp/rspec/its_ok_if_a_test_deletes_this/babushka"
end

FileUtils.rm_r tmp_prefix if File.exists? tmp_prefix
FileUtils.mkdir_p tmp_prefix unless File.exists? tmp_prefix
`rm -rf '#{tmp_prefix}'` if File.exists? tmp_prefix
`mkdir -p '#{tmp_prefix}'` unless File.exists? tmp_prefix

module Babushka
class Resource
Expand All @@ -27,7 +27,7 @@ def archive_prefix

class Source
def remove!
!cloneable? || !File.exists?(path) || FileUtils.rm_r(path)
!cloneable? || !File.exists?(path) || `rm -rf '#{path}'`
end
private
def self.sources_yml
Expand Down

0 comments on commit 67c5dd5

Please sign in to comment.