diff options
author | Antony Deepak Thomas <antonydeepak@gmail.com> | 2021-09-22 10:13:26 -0700 |
---|---|---|
committer | Antony Deepak Thomas <antonydeepak@gmail.com> | 2021-09-22 10:18:07 -0700 |
commit | 7330db78d29442a853974c61ba2a89dd58405203 (patch) | |
tree | e67f80c4f3451ea6f57cb6e9e1985c47cb8c761d | |
parent | 1759bb0b57bf1cd827b1c115b7f853df5c3b0400 (diff) | |
download | chef-7330db78d29442a853974c61ba2a89dd58405203.tar.gz |
Change rspec to reflect the behavior of JSONCompat
Signed-off-by: Antony Deepak Thomas <antonydeepak@gmail.com>
-rw-r--r-- | spec/unit/resource/file/verification/json_spec.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/spec/unit/resource/file/verification/json_spec.rb b/spec/unit/resource/file/verification/json_spec.rb index 22a769054d..749aee3e39 100644 --- a/spec/unit/resource/file/verification/json_spec.rb +++ b/spec/unit/resource/file/verification/json_spec.rb @@ -51,10 +51,16 @@ describe Chef::Resource::File::Verification::Json do expect(v.verify(@invalid_json)).to eq(false) end - it "returns false for empty file" do - # empty string is invalid per JSON spec https://stackoverflow.com/questions/30621802/why-does-json-parse-fail-with-the-empty-string + it "returns true for empty file" do + # Expectation here is different from that of default JSON parser included in ruby 2.4+. + # The default parser considers empty string as invalid JSON + # https://stackoverflow.com/questions/30621802/why-does-json-parse-fail-with-the-empty-string, + # however JSONCompat parses an empty string to `nil`. + # We are retaining the behavior of JSONCompat for two reasons + # - It is universal inside Chef codebase + # - It can be helpful to not throw an error when a `file` or `template` is empty v = Chef::Resource::File::Verification::Json.new(parent_resource, :json, {}) - expect(v.verify(@empty_json)).to eq(false) + expect(v.verify(@empty_json)).to eq(true) end end |