diff options
author | Salim Alam <salam@chef.io> | 2015-09-30 19:10:26 -0700 |
---|---|---|
committer | Salim Alam <salam@chef.io> | 2015-09-30 19:10:26 -0700 |
commit | 5ab3345d22a8941eab8b8e697c31ec7904f14d9d (patch) | |
tree | f8e731a90f85294f0aafbf5603ba01d14af1d841 | |
parent | 8832e75f2d6531b38195f3c8e3a809736788660e (diff) | |
download | chef-5ab3345d22a8941eab8b8e697c31ec7904f14d9d.tar.gz |
Clean up tests, fix bug in tempfile_open
-rw-r--r-- | lib/chef/file_content_management/tempfile.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/template/content_spec.rb | 20 |
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/chef/file_content_management/tempfile.rb b/lib/chef/file_content_management/tempfile.rb index 2dde0ce21b..6e1624f9a4 100644 --- a/lib/chef/file_content_management/tempfile.rb +++ b/lib/chef/file_content_management/tempfile.rb @@ -49,7 +49,7 @@ class Chef end end - raise Chef::Exceptions::FileContentStagingError(errors) if tf.nil? + raise Chef::Exceptions::FileContentStagingError, errors if tf.nil? # We always process the tempfile in binmode so that we # preserve the line endings of the content. diff --git a/spec/unit/provider/template/content_spec.rb b/spec/unit/provider/template/content_spec.rb index 925cbdfd6e..f2c3910c4b 100644 --- a/spec/unit/provider/template/content_spec.rb +++ b/spec/unit/provider/template/content_spec.rb @@ -21,11 +21,11 @@ require 'spec_helper' describe Chef::Provider::Template::Content do let(:enclosing_directory) { - canonicalize_path(File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks"))) + Dir.mktmpdir } let(:resource_path) { - canonicalize_path(File.expand_path(File.join(enclosing_directory, "openldap/templates/default/openldap_stuff.conf.erb"))) + canonicalize_path(File.expand_path(File.join(enclosing_directory, "openldap_stuff.conf"))) } let(:new_resource) do @@ -36,7 +36,7 @@ describe Chef::Provider::Template::Content do :source_line_file => "/Users/lamont/solo/cookbooks/openldap/recipes/default.rb", :source_line_number => "2", :source => 'openldap_stuff.conf.erb', - :name => 'openldap_stuff.conf.erb', + :name => 'openldap_stuff.conf', :path => resource_path, :local => false, :cookbook => nil, @@ -46,7 +46,10 @@ describe Chef::Provider::Template::Content do :helper_modules => []) end - let(:rendered_file_location) { Dir.tmpdir + '/openldap_stuff.conf' } + let(:rendered_file_locations) { + [Dir.tmpdir + '/openldap_stuff.conf', + enclosing_directory + '/openldap_stuff.conf'] + } let(:run_context) do cookbook_repo = File.expand_path(File.join(CHEF_SPEC_DATA, "cookbooks")) @@ -64,7 +67,9 @@ describe Chef::Provider::Template::Content do end after do - FileUtils.rm(rendered_file_location) if ::File.exist?(rendered_file_location) + rendered_file_locations.each do |file| + FileUtils.rm(file) if ::File.exist?(file) + end end it "finds the template file in the cookbook cache if it isn't local" do @@ -92,11 +97,10 @@ describe Chef::Provider::Template::Content do it "returns a tempfile in the destdir when :file_staging_uses_destdir is set" do Chef::Config[:file_staging_uses_destdir] = true - expect(content.tempfile.path.start_with?(Dir::tmpdir)).to be false expect(canonicalize_path(content.tempfile.path).start_with?(enclosing_directory)).to be true end - context "when creating a tempfiles in destdir fails" do + context "when creating a tempfile in destdir fails" do let(:enclosing_directory) { canonicalize_path("/nonexisting/path") } @@ -109,7 +113,7 @@ describe Chef::Provider::Template::Content do it "fails when :file_desployment_uses_destdir is set" do Chef::Config[:file_staging_uses_destdir] = true - expect{content.tempfile}.to raise_error + expect{content.tempfile}.to raise_error(Chef::Exceptions::FileContentStagingError) end it "returns a tempfile in the tempdir when :file_desployment_uses_destdir is not set" do |