diff options
-rw-r--r-- | lib/chef/resource/file/verification.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/file/verification_spec.rb | 20 |
2 files changed, 18 insertions, 6 deletions
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index f1ca0f1883..6be1f912fd 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -106,7 +106,9 @@ class Chef # We reuse Chef::GuardInterpreter in order to support # the same set of options that the not_if/only_if blocks do def verify_command(path, opts) - command = @command % {:file => path} + # First implementation interpolated `file`; docs & RFC claim `path` + # is interpolated. Until `file` can be deprecated, interpolate both. + command = @command % {:file => path, :path => path} interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts) interpreter.evaluate end diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index 3609d9d482..0ab4ce28e6 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -69,12 +69,22 @@ describe Chef::Resource::File::Verification do end context "with a verification command(String)" do + def platform_specific_verify_command(variable_name) + if windows? + "if \"#{temp_path}\" == \"%{#{variable_name}}\" (exit 0) else (exit 1)" + else + "test #{temp_path} = %{#{variable_name}}" + end + end + it "substitutes \%{file} with the path" do - test_command = if windows? - "if \"#{temp_path}\" == \"%{file}\" (exit 0) else (exit 1)" - else - "test #{temp_path} = %{file}" - end + test_command = platform_specific_verify_command('file') + v = Chef::Resource::File::Verification.new(parent_resource, test_command, {}) + expect(v.verify(temp_path)).to eq(true) + end + + it "substitutes \%{path} with the path" do + test_command = platform_specific_verify_command('path') v = Chef::Resource::File::Verification.new(parent_resource, test_command, {}) expect(v.verify(temp_path)).to eq(true) end |