1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Do not use YAML module in tests of Psych

This commit is contained in:
Hiroshi SHIBATA 2021-06-07 19:24:20 +09:00
parent d7146dfd7d
commit bb4a10208c
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2

View file

@ -393,7 +393,7 @@ booleans:
- false
eoyml
payload = YAML.safe_dump({
payload = Psych.safe_dump({
"array" => [1],
"float" => 13.12,
"booleans" => [true, false],
@ -403,39 +403,39 @@ eoyml
def test_safe_dump_unpermitted_class
error = assert_raise Psych::DisallowedClass do
YAML.safe_dump(Object.new)
Psych.safe_dump(Object.new)
end
assert_equal "Tried to dump unspecified class: Object", error.message
hash_subclass = Class.new(Hash)
error = assert_raise Psych::DisallowedClass do
YAML.safe_dump(hash_subclass.new)
Psych.safe_dump(hash_subclass.new)
end
assert_equal "Tried to dump unspecified class: #{hash_subclass.inspect}", error.message
end
def test_safe_dump_extra_permitted_classes
assert_equal "--- !ruby/object {}\n", YAML.safe_dump(Object.new, permitted_classes: [Object])
assert_equal "--- !ruby/object {}\n", Psych.safe_dump(Object.new, permitted_classes: [Object])
end
def test_safe_dump_symbols
error = assert_raise Psych::DisallowedClass do
YAML.safe_dump(:foo, permitted_classes: [Symbol])
Psych.safe_dump(:foo, permitted_classes: [Symbol])
end
assert_equal "Tried to dump unspecified class: Symbol(:foo)", error.message
assert_equal "--- :foo\n", YAML.safe_dump(:foo, permitted_classes: [Symbol], permitted_symbols: [:foo])
assert_equal "--- :foo\n", Psych.safe_dump(:foo, permitted_classes: [Symbol], permitted_symbols: [:foo])
end
def test_safe_dump_aliases
x = []
x << x
error = assert_raise Psych::BadAlias do
YAML.safe_dump(x)
Psych.safe_dump(x)
end
assert_equal "Tried to dump an aliased object", error.message
assert_equal "--- &1\n" + "- *1\n", YAML.safe_dump(x, aliases: true)
assert_equal "--- &1\n" + "- *1\n", Psych.safe_dump(x, aliases: true)
end
end