summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcuriositycasualty <isa@getchef.com>2014-10-14 12:24:54 -0700
committercuriositycasualty <isa@getchef.com>2014-10-28 11:56:43 -0700
commitb09abbab21f835c39cf82996fbc4bd49c0192932 (patch)
treeaade619c207f6a703b97a658a71fdb3e401b28c4
parent8c06a8c16f4e1dd124415514082359e3dcef6f89 (diff)
downloadchef-b09abbab21f835c39cf82996fbc4bd49c0192932.tar.gz
add empty? method for cheffs base dir class
add spec tests remove commented pry binding delegate to Array#empty? instead
-rw-r--r--lib/chef/chef_fs/file_system/base_fs_dir.rb5
-rw-r--r--spec/unit/chef_fs/file_system_spec.rb23
2 files changed, 23 insertions, 5 deletions
diff --git a/lib/chef/chef_fs/file_system/base_fs_dir.rb b/lib/chef/chef_fs/file_system/base_fs_dir.rb
index 74038f481b..8cc277facc 100644
--- a/lib/chef/chef_fs/file_system/base_fs_dir.rb
+++ b/lib/chef/chef_fs/file_system/base_fs_dir.rb
@@ -40,6 +40,11 @@ class Chef
true
end
+ # An empty children array is an empty dir
+ def empty?
+ children.empty?
+ end
+
# Abstract: children
end
end
diff --git a/spec/unit/chef_fs/file_system_spec.rb b/spec/unit/chef_fs/file_system_spec.rb
index 383a2c81ab..50f20a7a1c 100644
--- a/spec/unit/chef_fs/file_system_spec.rb
+++ b/spec/unit/chef_fs/file_system_spec.rb
@@ -66,18 +66,19 @@ describe Chef::ChefFS::FileSystem do
:c => '',
}
},
- :x => ''
+ :x => '',
+ :y => {}
})
}
context 'list' do
it '/**' do
- list_should_yield_paths(fs, '/**', '/', '/a', '/x', '/a/aa', '/a/aa/c', '/a/aa/zz', '/a/ab', '/a/ab/c')
+ list_should_yield_paths(fs, '/**', '/', '/a', '/x', '/y', '/a/aa', '/a/aa/c', '/a/aa/zz', '/a/ab', '/a/ab/c')
end
it '/' do
list_should_yield_paths(fs, '/', '/')
end
it '/*' do
- list_should_yield_paths(fs, '/*', '/', '/a', '/x')
+ list_should_yield_paths(fs, '/*', '/', '/a', '/x', '/y')
end
it '/*/*' do
list_should_yield_paths(fs, '/*/*', '/a/aa', '/a/ab')
@@ -127,8 +128,20 @@ describe Chef::ChefFS::FileSystem do
it 'resolves /a/aa/zz' do
Chef::ChefFS::FileSystem.resolve_path(fs, '/a/aa/zz').path.should == '/a/aa/zz'
end
- it 'resolves nonexistent /y/x/w' do
- Chef::ChefFS::FileSystem.resolve_path(fs, '/y/x/w').path.should == '/y/x/w'
+ it 'resolves nonexistent /q/x/w' do
+ Chef::ChefFS::FileSystem.resolve_path(fs, '/q/x/w').path.should == '/q/x/w'
+ end
+ end
+
+ context 'empty?' do
+ it 'is not empty /' do
+ Chef::ChefFS::FileSystem.resolve_path(fs, '/').empty?.should be false
+ end
+ it 'is empty /y' do
+ Chef::ChefFS::FileSystem.resolve_path(fs, '/y').empty?.should be true
+ end
+ it 'is not a directory and can\'t be tested /x' do
+ lambda { Chef::ChefFS::FileSystem.resolve_path(fs, '/x').empty? }.should raise_error(NoMethodError)
end
end
end