summaryrefslogtreecommitdiff
path: root/dev-ruby/safe_yaml/files/safe_yaml-1.0.5-ruby30-openstruct-tests.patch
blob: 9b597276617b8301dc13ff28761a2d59772a1409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
From: Sergio Durigan Junior <sergiodj@debian.org>
Date: Fri, 28 Jan 2022 16:35:01 -0500
Subject: Adjust tests to reflect OpenStruct changes on Ruby3.0

Ref.: https://github.com/ruby/psych/issues/540

OpenStruct on Ruby3.0 changed its marshalling/unmarshalling code,
which is now impacting safe_yaml's testcase.  The two adjustments that
needed to be made are:

- OpenStruct's instance_variable_get will now symbolize its hash keys,
  instead of using strings.

- OpenStruct's to_yaml method will not output the 'table' entity
  anymore.

Signed-off-by: Sergio Durigan Junior <sergiodj@sergiodj.net>

Forwarded: yes, https://github.com/dtao/safe_yaml/pull/102
---
 spec/safe_yaml_spec.rb | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/spec/safe_yaml_spec.rb b/spec/safe_yaml_spec.rb
index aa701a4..1081173 100644
--- a/spec/safe_yaml_spec.rb
+++ b/spec/safe_yaml_spec.rb
@@ -318,7 +318,13 @@ describe YAML do
       it "will allow objects to be deserialized for whitelisted tags" do
         result = YAML.safe_load("--- !ruby/object:OpenStruct\ntable:\n  foo: bar\n")
         expect(result).to be_a(OpenStruct)
-        expect(result.instance_variable_get(:@table)).to eq({ "foo" => "bar" })
+        if RUBY_VERSION < '3.0'
+          expect(result.instance_variable_get(:@table)).to eq({ "foo" => "bar" })
+        else
+          # Ruby3.0's OpenStruct will now symbolize the hash key.
+          # Ref.: https://github.com/ruby/psych/issues/540
+          expect(result.instance_variable_get(:@table)).to eq({ :foo => "bar" })
+        end
       end
 
       it "will not deserialize objects without whitelisted tags" do
@@ -463,10 +469,24 @@ describe YAML do
 
         it "allows the default option to be overridden on a per-call basis" do
           result = safe_load_round_trip(OpenStruct.new(:foo => "bar"), :whitelisted_tags => [])
-          expect(result).to eq({ "table" => { :foo => "bar" } })
+          if RUBY_VERSION < '3.0'
+            expect(result).to eq({ "table" => { :foo => "bar" } })
+          else
+            # Ruby3.0's OpenStruct's to_yaml method doesn't output the
+            # 'table' entity anymore.
+            # Ref.: https://github.com/ruby/psych/issues/540
+            expect(result).to eq({ "foo" => "bar" })
+          end
 
           result = safe_load_round_trip(OpenStruct.new(:foo => "bar"), :deserialize_symbols => false, :whitelisted_tags => [])
-          expect(result).to eq({ "table" => { ":foo" => "bar" } })
+          if RUBY_VERSION < '3.0'
+            expect(result).to eq({ "table" => { ":foo" => "bar" } })
+          else
+            # Ruby3.0's OpenStruct's to_yaml method doesn't output the
+            # 'table' entity anymore.
+            # Ref.: https://github.com/ruby/psych/issues/540
+            expect(result).to eq({ "foo" => "bar" })
+          end
         end
       end
     end