Skip to content

Commit

Permalink
empty?
Browse files Browse the repository at this point in the history
  • Loading branch information
Myles Byrne committed Jul 12, 2009
1 parent 9c107b7 commit 97ecec1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fancypath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ def select(*args)
Dir["#{self}/#{arg}"].map { |p| self.class.new(p) }
end
end


def empty?
directory? ? children.size == 0 : self.size == 0
end

def inspect
super.sub('Pathname','Fancypath')
end
Expand Down
25 changes: 25 additions & 0 deletions spec/fancypath_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@

end

describe '#empty?' do

example 'with empty file' do
@file.touch
@file.empty?.should be_true
end

example 'with non-empty file' do
@file.write 'foo'
@file.empty?.should be_false
end

example 'with empty dir' do
@dir.create_dir
@dir.empty?.should be_true
end

example 'with non-empty dir' do
@dir.create_dir
(@dir/'foo').touch
@dir.empty?.should be_false
end

end

end #/Fancypath

describe "String#to_path" do
Expand Down

0 comments on commit 97ecec1

Please sign in to comment.