summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcuriositycasualty <isa@getchef.com>2014-10-14 12:24:54 -0700
committercuriositycasualty <isa@getchef.com>2014-10-22 12:17:35 -0700
commit59a1a0aed54be5d9b4151b063f84a3e1db94cfd1 (patch)
tree6ceaa9511cfa05ad70411ef016dc391e75d309af
parent8c06a8c16f4e1dd124415514082359e3dcef6f89 (diff)
downloadchef-59a1a0aed54be5d9b4151b063f84a3e1db94cfd1.tar.gz
add empty? method for cheffs base dir class
add spec tests
-rw-r--r--lib/chef/chef_fs/file_system/base_fs_dir.rb5
-rw-r--r--spec/unit/chef_fs/file_system_spec.rb24
2 files changed, 24 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..87e57285b8 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
+ # A dir without children is empty
+ def empty?
+ children == []
+ 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..7ac413857d 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,21 @@ 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
+#require 'pry'; binding.pry
+ lambda { Chef::ChefFS::FileSystem.resolve_path(fs, '/x').empty? }.should raise_error(NoMethodError)
end
end
end