You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.8 KiB
70 lines
2.8 KiB
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
|