diff options
author | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-09-27 10:16:12 +0530 |
---|---|---|
committer | Vivek Singh <vivek.singh@msystechnologies.com> | 2019-09-27 10:16:12 +0530 |
commit | 1a049aa3a42d8ce785afdbe8467d249991baf2c4 (patch) | |
tree | 4c60c42a2408b7c63bf7b1a76e6496bf30bed31d /spec | |
parent | 49ff9da07c01255c36650ca55874ac067c0e68bd (diff) | |
download | chef-1a049aa3a42d8ce785afdbe8467d249991baf2c4.tar.gz |
Override the #to_yaml method for ImmutableMash & ImmutableArray
- Psych module to_yaml not working as expected for ImmutableMash & ImmutableArray.
- So parse first to Hash/Array then convert it to YAML formatted string.
Signed-off-by: Vivek Singh <vivek.singh@msystechnologies.com>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/node/immutable_collections_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/unit/node/immutable_collections_spec.rb b/spec/unit/node/immutable_collections_spec.rb index f23e40dc4c..e9697c320f 100644 --- a/spec/unit/node/immutable_collections_spec.rb +++ b/spec/unit/node/immutable_collections_spec.rb @@ -145,6 +145,20 @@ describe Chef::Node::ImmutableMash do end end + describe "to_yaml" do + before do + @copy = @immutable_mash.to_yaml + end + + it "converts an immutable mash to a new mutable YAML formatted string" do + expect(@copy).to be_instance_of(String) + end + + it "should create a YAML formatted string with the content" do + expect(@copy).to eq("---\ntop:\n second_level: some value\ntop_level_2:\n- array\n- of\n- values\ntop_level_3:\n- hash_array: 1\n hash_array_b: 2\ntop_level_4:\n level2:\n key: value\n") + end + end + %i{ []= clear @@ -318,6 +332,20 @@ describe Chef::Node::ImmutableArray do end end + describe "to_yaml" do + before do + @copy = @immutable_nested_array.to_yaml + end + + it "converts an immutable array to a new YAML formatted mutable string" do + expect(@copy).to be_instance_of(String) + end + + it "should create a YAML formatted string with content" do + expect(@copy).to eq("---\n- level1\n- - foo\n - bar\n - baz\n - 1\n - 2\n - 3\n - \n - true\n - false\n - - el\n - 0\n - \n- m: m\n") + end + end + describe "#[]" do it "works with array slices" do expect(@immutable_array[1, 2]).to eql(%w{bar baz}) |