diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-12-02 15:47:32 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-12-02 15:47:32 +0530 |
commit | 52871d2c8d8bc8ed526b8e3eda9aadb5fa0f93e5 (patch) | |
tree | e82909630080293ed9b2a829cd9d77d904125712 /spec | |
parent | 6deede271dd01f0aad393d1264aba45a0a22d6f0 (diff) | |
download | chef-52871d2c8d8bc8ed526b8e3eda9aadb5fa0f93e5.tar.gz |
Fix undefined method `dirname' for Chef::Provider::File:Classlcg/file-verifier-output
- Fix failing specs.
- Fix long strings getting truncated for RSpec expectations.
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/unit/provider/file.rb | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 27cf301d67..3154e2f255 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -123,8 +123,10 @@ RSpec.configure do |config| config.filter_run_excluding external: true # Explicitly disable :should syntax + # And set max_formatted_output_length to nil to prevent RSpec from doing truncation. config.expect_with :rspec do |c| c.syntax = :expect + c.max_formatted_output_length = nil end config.mock_with :rspec do |c| c.syntax = :expect diff --git a/spec/support/shared/unit/provider/file.rb b/spec/support/shared/unit/provider/file.rb index 36b19675c2..3df8eecc6f 100644 --- a/spec/support/shared/unit/provider/file.rb +++ b/spec/support/shared/unit/provider/file.rb @@ -458,14 +458,24 @@ shared_examples_for Chef::Provider::File do end context "do_validate_content" do - before { setup_normal_file } + let(:tempfile_name) { "foo-bar-baz" } + let(:backupfile) { "/tmp/failed_validations/#{tempfile_name}" } let(:tempfile) do - t = double("Tempfile", path: "/tmp/foo-bar-baz", closed?: true) + t = double("Tempfile", path: "/tmp/#{tempfile_name}", closed?: true) allow(content).to receive(:tempfile).and_return(t) t end + before do + Chef::Config[:file_cache_path] = "/tmp" + allow(File).to receive(:dirname).and_return(tempfile) + allow(File).to receive(:basename).and_return(tempfile_name) + allow(FileUtils).to receive(:mkdir_p).and_return(true) + allow(FileUtils).to receive(:cp).and_return(true) + setup_normal_file + end + context "with user-supplied verifications" do it "calls #verify on each verification with tempfile path" do provider.new_resource.verify windows? ? "REM" : "true" @@ -477,7 +487,8 @@ shared_examples_for Chef::Provider::File do allow(File).to receive(:directory?).with("C:\\Windows\\system32/cmd.exe").and_return(false) provider.new_resource.verify windows? ? "REM" : "true" provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false" - expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}") + msg = "Proposed content for #{provider.new_resource.path} failed verification #{windows? ? "cmd.exe /c exit 1" : "false"}" + expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, /#{msg}/) end it "does not show verification for sensitive resources" do @@ -485,7 +496,8 @@ shared_examples_for Chef::Provider::File do provider.new_resource.verify windows? ? "REM" : "true" provider.new_resource.verify windows? ? "cmd.exe /c exit 1" : "false" provider.new_resource.sensitive true - expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, "Proposed content for #{provider.new_resource.path} failed verification [sensitive]") + msg = "Proposed content for #{provider.new_resource.path} failed verification [sensitive]\nTemporary file moved to #{backupfile}" + expect { provider.send(:do_validate_content) }.to raise_error(Chef::Exceptions::ValidationFailed, msg) end end end |