diff options
author | Isa Farnik <isa@getchef.com> | 2014-10-28 12:04:20 -0700 |
---|---|---|
committer | Isa Farnik <isa@getchef.com> | 2014-10-28 12:04:20 -0700 |
commit | 3f1dd3fbbf7fa9907fc73fc8ee1f0daebed258dc (patch) | |
tree | c6327a4139e1a0a73a90ba5f47808183c6bb4e3a | |
parent | 5bb183ab18d15374aa0a1b8ea91aaa1557d8d8e4 (diff) | |
parent | b09abbab21f835c39cf82996fbc4bd49c0192932 (diff) | |
download | chef-3f1dd3fbbf7fa9907fc73fc8ee1f0daebed258dc.tar.gz |
Merge pull request #2230 from opscode/if/add-cheffs-empty-check
Add #empty? method to the ChefFS base dir class.
-rw-r--r-- | lib/chef/chef_fs/file_system/base_fs_dir.rb | 5 | ||||
-rw-r--r-- | spec/unit/chef_fs/file_system_spec.rb | 23 |
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 |