Skip to content

Commit

Permalink
Merge pull request #567 from ftnk/add_content_as_yaml
Browse files Browse the repository at this point in the history
add `its(:content_as_yaml)` to file resource type
  • Loading branch information
mizzy committed May 15, 2016
2 parents 5404e89 + 9d5e778 commit d05b6dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/serverspec/type/file.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'date'
require 'multi_json'
require 'yaml'

module Serverspec::Type
class File < Base
Expand Down Expand Up @@ -119,6 +120,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
Expand Down
19 changes: 19 additions & 0 deletions spec/type/base/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) {<<EOF
---
yaml:
title: 'this is a yaml'
array:
-
title: 'array 1'
-
title: 'array 2'
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'))) }
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' }
Expand Down

0 comments on commit d05b6dc

Please sign in to comment.