Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Psych 4.0 (Ruby 3.1) or later #620

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/serverspec/type/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ def content_as_json
end

def content_as_yaml
@content_as_yaml = YAML.load(content) if @content_as_yaml.nil?
if @content_as_yaml.nil?
@content_as_yaml = if YAML.respond_to?(:unsafe_load)
YAML.unsafe_load(content)
else
YAML.load(content)
end
end
@content_as_yaml
end

Expand Down
6 changes: 5 additions & 1 deletion spec/type/base/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,22 @@
let(:stdout) {<<EOF
---
yaml:
title: 'this is a yaml'
title: &anchor 'this is a yaml'
array:
-
title: 'array 1'
-
title: 'array 2'
date: 2023-02-03
Reuse anchor: *anchor
EOF
}

its(:content_as_yaml) { should include('yaml') }
its(:content_as_yaml) { should include('yaml' => include('title' => 'this is a yaml')) }
its(:content_as_yaml) { should include('yaml' => include('array' => include('title' => 'array 2'))) }
its(:content_as_yaml) { should include('yaml' => include('date' => Date.new(2023, 2, 3))) }
its(:content_as_yaml) { should include('yaml' => include('Reuse anchor' => 'this is a yaml')) }
end


Expand Down