From 9d5e778499fe853a95e667a9e1261056968ffd15 Mon Sep 17 00:00:00 2001 From: Fumihisa TONAKA Date: Wed, 11 May 2016 05:10:48 +0900 Subject: [PATCH] add `its(:content_as_yaml)` to file resource type --- lib/serverspec/type/file.rb | 6 ++++++ spec/type/base/file_spec.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/serverspec/type/file.rb b/lib/serverspec/type/file.rb index 85a8853f..346768c8 100644 --- a/lib/serverspec/type/file.rb +++ b/lib/serverspec/type/file.rb @@ -1,5 +1,6 @@ require 'date' require 'multi_json' +require 'yaml' module Serverspec::Type class File < Base @@ -122,6 +123,11 @@ def content_as_json @content_as_json end + def content_as_yaml + @content_as_yaml = YAML.load(content) if @content_as_yaml.nil? + @content_as_yaml + end + def group @runner.get_file_owner_group(@name).stdout.strip end diff --git a/spec/type/base/file_spec.rb b/spec/type/base/file_spec.rb index 57f65c56..e5c8f1b5 100644 --- a/spec/type/base/file_spec.rb +++ b/spec/type/base/file_spec.rb @@ -365,6 +365,25 @@ its(:content_as_json) { should include('json' => include('array' => include('title' => 'array 2'))) } end +describe file('example.yml') do + let(:stdout) {< include('title' => 'this is a yaml')) } + its(:content_as_yaml) { should include('yaml' => include('array' => include('title' => 'array 2'))) } +end + + describe file('/etc/pam.d/system-auth') do let(:stdout) { "/etc/pam.dsystem-auth-ac\r\n" } its(:link_target) { should eq '/etc/pam.dsystem-auth-ac' }