diff options
author | Lamont Granquist <lamont@opscode.com> | 2013-03-25 13:06:41 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@opscode.com> | 2013-03-25 13:06:41 -0700 |
commit | 9de1da01124e549ac514488d2dc71ffb46c9b57e (patch) | |
tree | b7100ddd1c9eca786d8d5ebf3a9004fe5c214573 | |
parent | db72ae9f28a3eaf27c8e8af5815f7b030186ef07 (diff) | |
download | chef-9de1da01124e549ac514488d2dc71ffb46c9b57e.tar.gz |
moar spec test fixes
-rw-r--r-- | lib/chef/provider/directory.rb | 10 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/cookbook_file_spec.rb | 79 | ||||
-rw-r--r-- | spec/unit/provider/directory_spec.rb | 36 |
4 files changed, 40 insertions, 87 deletions
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb index e6886dde59..3de970ab1d 100644 --- a/lib/chef/provider/directory.rb +++ b/lib/chef/provider/directory.rb @@ -54,7 +54,7 @@ class Chef # make sure we have write permissions to that directory is_parent_writable = lambda do |base_dir| base_dir = ::File.dirname(base_dir) - if ::File.exist?(base_dir) + if ::File.exists?(base_dir) ::File.writable?(base_dir) else is_parent_writable.call(base_dir) @@ -64,7 +64,7 @@ class Chef else # in why run mode & parent directory does not exist no permissions check is required # If not in why run, permissions must be valid and we rely on prior assertion that dir exists - if !whyrun_mode? || ::File.exist?(parent_directory) + if !whyrun_mode? || ::File.exists?(parent_directory) ::File.writable?(parent_directory) else true @@ -77,7 +77,7 @@ class Chef requirements.assert(:delete) do |a| a.assertion do - if ::File.exist?(@new_resource.path) + if ::File.exists?(@new_resource.path) ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path) else true @@ -91,7 +91,7 @@ class Chef end def action_create - unless ::File.exist?(@new_resource.path) + unless ::File.exists?(@new_resource.path) converge_by("create new directory #{@new_resource.path}") do if @new_resource.recursive == true ::FileUtils.mkdir_p(@new_resource.path) @@ -106,7 +106,7 @@ class Chef end def action_delete - if ::File.exist?(@new_resource.path) + if ::File.exists?(@new_resource.path) converge_by("delete existing directory #{@new_resource.path}") do if @new_resource.recursive == true FileUtils.rm_rf(@new_resource.path) diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index e86addbe3f..1b95639607 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -361,6 +361,8 @@ shared_examples_for Chef::Provider::File do context "do_contents_changes" do context "when there is content to deploy" do before do + setup_normal_file + provider.load_current_resource tempfile = double('Tempfile', :path => "/tmp/foo-bar-baz") content.stub!(:tempfile).and_return(tempfile) File.should_receive(:exists?).with("/tmp/foo-bar-baz").and_return(true) diff --git a/spec/unit/provider/cookbook_file_spec.rb b/spec/unit/provider/cookbook_file_spec.rb index 35025ee970..c00f28f855 100644 --- a/spec/unit/provider/cookbook_file_spec.rb +++ b/spec/unit/provider/cookbook_file_spec.rb @@ -37,69 +37,20 @@ describe Chef::Provider::CookbookFile do it_behaves_like Chef::Provider::File -# before do -# Chef::FileAccessControl.any_instance.stub(:set_all) -# Chef::FileAccessControl.any_instance.stub(:modified?).and_return(true) -# @cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) -# Chef::Cookbook::FileVendor.on_create { |manifest| Chef::Cookbook::FileSystemFileVendor.new(manifest, @cookbook_repo) } -# -# @node = Chef::Node.new -# @events = Chef::EventDispatch::Dispatcher.new -# cl = Chef::CookbookLoader.new(@cookbook_repo) -# cl.load_cookbooks -# @cookbook_collection = Chef::CookbookCollection.new(cl) -# @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events) -# -# @new_resource = Chef::Resource::CookbookFile.new('apache2_module_conf_generate.pl', @run_context) -# @new_resource.cookbook_name = 'apache2' -# @provider = Chef::Provider::CookbookFile.new(@new_resource, @run_context) -# -# @file_content=<<-EXPECTED -## apache2_module_conf_generate.pl -## this is just here for show. -#EXPECTED -# -# end - -# FIXME: move to Chef::Provider::File -# describe "when loading the current file state" do -# -# it "converts windows-y filenames to unix-y ones" do -# @new_resource.path('windows\stuff') -# @provider.load_current_resource -# @new_resource.path.should == 'windows/stuff' -# end -# -# it "sets the current resources path to the same as the new resource" do -# @new_resource.path('/tmp/file') -# @provider.load_current_resource -# @provider.current_resource.path.should == '/tmp/file' -# end -# end - - describe "when the file doesn't yet exist" do - before do - @install_to = Dir.tmpdir + '/apache2_modconf.pl' - - @current_resource = @new_resource.dup - @provider.current_resource = @current_resource - end - - after { ::File.exist?(File.dirname(@install_to)) && FileUtils.rm_rf(@install_to) } - - it "looks up a file from the cookbook cache" do - expected = CHEF_SPEC_DATA + "/cookbooks/apache2/files/default/apache2_module_conf_generate.pl" - @provider.file_cache_location.should == expected - end - - it "installs the file from the cookbook cache" do - @new_resource.path(@install_to) - @provider.should_receive(:backup_new_resource) - @provider.stub!(:update_new_file_state) - @provider.run_action(:create) - actual = IO.read(@install_to) - actual.should == @file_content - end - end + # FIXME: move to Chef::Provider::File + # describe "when loading the current file state" do + # + # it "converts windows-y filenames to unix-y ones" do + # @new_resource.path('windows\stuff') + # @provider.load_current_resource + # @new_resource.path.should == 'windows/stuff' + # end + # + # it "sets the current resources path to the same as the new resource" do + # @new_resource.path('/tmp/file') + # @provider.load_current_resource + # @provider.current_resource.path.should == '/tmp/file' + # end + # end end diff --git a/spec/unit/provider/directory_spec.rb b/spec/unit/provider/directory_spec.rb index 3936525903..0b7d040210 100644 --- a/spec/unit/provider/directory_spec.rb +++ b/spec/unit/provider/directory_spec.rb @@ -59,7 +59,7 @@ describe Chef::Provider::Directory do end it "describes the access mode as a String of octal integers" do - File.stub!(:exist?).and_return(true) + File.stub!(:exists?).and_return(true) File.should_receive(:stat).and_return(mock_stat) @directory.load_current_resource @directory.current_resource.mode.should == "0755" @@ -67,7 +67,7 @@ describe Chef::Provider::Directory do context "when user and group are specified with UID/GID" do it "describes the current owner and group as UID and GID" do - File.stub!(:exist?).and_return(true) + File.stub!(:exists?).and_return(true) File.should_receive(:stat).and_return(mock_stat) @directory.load_current_resource @directory.current_resource.path.should eql(@new_resource.path) @@ -81,16 +81,16 @@ describe Chef::Provider::Directory do end # Unix only for now. While file security attribute reporting for windows is - # disabled, unix and windows differ in the number of exist? calls that are + # disabled, unix and windows differ in the number of exists? calls that are # made by the provider. it "should create a new directory on create, setting updated to true", :unix_only do @new_resource.path "/tmp/foo" - File.should_receive(:exist?).exactly(2).and_return(false) + File.should_receive(:exists?).at_least(:once).and_return(false) File.should_receive(:directory?).with("/tmp").and_return(true) Dir.should_receive(:mkdir).with(@new_resource.path).once.and_return(true) - @directory.should_receive(:set_all_access_controls) + @directory.should_receive(:do_acl_changes) @directory.stub!(:update_new_file_state) @directory.run_action(:create) @directory.new_resource.should be_updated @@ -103,20 +103,20 @@ describe Chef::Provider::Directory do end # Unix only for now. While file security attribute reporting for windows is - # disabled, unix and windows differ in the number of exist? calls that are + # disabled, unix and windows differ in the number of exists? calls that are # made by the provider. it "should create a new directory when parent directory does not exist if recursive is true and permissions are correct", :unix_only do @new_resource.path "/path/to/dir" @new_resource.recursive true - File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false) + File.should_receive(:exists?).with(@new_resource.path).ordered.and_return(false) - File.should_receive(:exist?).with('/path/to').ordered.and_return(false) - File.should_receive(:exist?).with('/path').ordered.and_return(true) + File.should_receive(:exists?).with('/path/to').ordered.and_return(false) + File.should_receive(:exists?).with('/path').ordered.and_return(true) File.should_receive(:writable?).with('/path').ordered.and_return(true) - File.should_receive(:exist?).with(@new_resource.path).ordered.and_return(false) + File.should_receive(:exists?).with(@new_resource.path).ordered.and_return(false) FileUtils.should_receive(:mkdir_p).with(@new_resource.path).and_return(true) - @directory.should_receive(:set_all_access_controls) + @directory.should_receive(:do_acl_changes) @directory.stub!(:update_new_file_state) @directory.run_action(:create) @new_resource.should be_updated @@ -131,16 +131,16 @@ describe Chef::Provider::Directory do end # Unix only for now. While file security attribute reporting for windows is - # disabled, unix and windows differ in the number of exist? calls that are + # disabled, unix and windows differ in the number of exists? calls that are # made by the provider. it "should not create the directory if it already exists", :unix_only do stub_file_cstats @new_resource.path "/tmp/foo" - File.should_receive(:directory?).twice.and_return(true) + File.should_receive(:directory?).at_least(:once).and_return(true) File.should_receive(:writable?).with("/tmp").and_return(true) - File.should_receive(:exist?).exactly(3).and_return(true) + File.should_receive(:exists?).at_least(:once).and_return(true) Dir.should_not_receive(:mkdir).with(@new_resource.path) - @directory.should_receive(:set_all_access_controls) + @directory.should_receive(:do_acl_changes) @directory.run_action(:create) end @@ -152,14 +152,14 @@ describe Chef::Provider::Directory do end it "should raise an exception if it cannot delete the directory due to bad permissions" do - File.stub!(:exist?).and_return(true) + File.stub!(:exists?).and_return(true) File.stub!(:writable?).and_return(false) lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) end it "should take no action when deleting a target directory that does not exist" do @new_resource.path "/an/invalid/path" - File.stub!(:exist?).and_return(false) + File.stub!(:exists?).and_return(false) Dir.should_not_receive(:delete).with(@new_resource.path) @directory.run_action(:delete) @directory.new_resource.should_not be_updated @@ -168,7 +168,7 @@ describe Chef::Provider::Directory do it "should raise an exception when deleting a directory when target directory is a file" do stub_file_cstats @new_resource.path "/an/invalid/path" - File.stub!(:exist?).and_return(true) + File.stub!(:exists?).and_return(true) File.should_receive(:directory?).and_return(false) Dir.should_not_receive(:delete).with(@new_resource.path) lambda { @directory.run_action(:delete) }.should raise_error(RuntimeError) |