Skip to content

Commit

Permalink
Merge pull request #564 from takaishi/add_resource_type_for_json_file
Browse files Browse the repository at this point in the history
add resource type json file
  • Loading branch information
mizzy committed Apr 28, 2016
2 parents 85b4177 + c6985cd commit 79751f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/serverspec/helper/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Type
types = %w(
base bridge bond cgroup command cron default_gateway file fstab
group host iis_website iis_app_pool interface ipfilter ipnat
iptables ip6tables kernel_module linux_kernel_parameter lxc
iptables ip6tables json_file kernel_module linux_kernel_parameter lxc
mail_alias mysql_config package php_config port ppa process
routing_table selinux selinux_module service user yumrepo
windows_feature windows_hot_fix windows_registry_key
Expand Down
9 changes: 9 additions & 0 deletions lib/serverspec/type/json_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'json'

module Serverspec::Type
class JsonFile < File
def content
JSON.parse(super)
end
end
end
27 changes: 27 additions & 0 deletions spec/type/base/json_file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'spec_helper'

set :os, {:family => 'base'}

describe json_file('example.json') do
let(:stdout) {<<EOF
{
"json": {
"title": "this is a json",
"array" : [
{
"title": "array 1"
},
{
"title": "array 2"
}
]
}
}
EOF
}

its(:content) { should include('json') }
its(:content) { should include('json' => include('title' => 'this is a json')) }
its(:content) { should include('json' => include('array' => include('title' => 'array 2'))) }
end

0 comments on commit 79751f8

Please sign in to comment.