Skip to content

Instantly share code, notes, and snippets.

@poloka
Last active January 11, 2022 01:03
Show Gist options
  • Save poloka/1448ded1b954c7e0e25a45ba523ddd63 to your computer and use it in GitHub Desktop.
Save poloka/1448ded1b954c7e0e25a45ba523ddd63 to your computer and use it in GitHub Desktop.
psych load/safe_load tests
require 'yaml'
require 'erb'
def file_path
file_path = File.join(Dir.pwd, 'test.yml')
end
def call_function(func, **options)
puts '*' * 100
puts "Testing 'YAML.#{func}' with options: #{options} using psych-#{Psych::VERSION} on #{RUBY_VERSION}"
content = YAML.send(func, ERB.new(File.read(file_path)).result, **options)
puts content
rescue Psych::DisallowedClass, Psych::BadAlias, Errno::ENOENT => e
puts "Error loading the '#{file_path}' located at '#{file_path}'. #{e.message}"
puts "Backtrace:\n\t#{e.backtrace.join("\n\t")}"
end
call_function(:safe_load)
call_function(:safe_load, aliases: true)
call_function(:load)
call_function(:load, aliases: true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment