From c6985cd11470eb8c68559a121897ad1ab69f49f5 Mon Sep 17 00:00:00 2001 From: Ryo TAKAISHI Date: Mon, 25 Apr 2016 21:08:46 +0900 Subject: [PATCH] add resource type json file --- lib/serverspec/helper/type.rb | 2 +- lib/serverspec/type/json_file.rb | 9 +++++++++ spec/type/base/json_file_spec.rb | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 lib/serverspec/type/json_file.rb create mode 100644 spec/type/base/json_file_spec.rb diff --git a/lib/serverspec/helper/type.rb b/lib/serverspec/helper/type.rb index c8bacf1e..ac375116 100644 --- a/lib/serverspec/helper/type.rb +++ b/lib/serverspec/helper/type.rb @@ -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 diff --git a/lib/serverspec/type/json_file.rb b/lib/serverspec/type/json_file.rb new file mode 100644 index 00000000..6b1e5f12 --- /dev/null +++ b/lib/serverspec/type/json_file.rb @@ -0,0 +1,9 @@ +require 'json' + +module Serverspec::Type + class JsonFile < File + def content + JSON.parse(super) + end + end +end diff --git a/spec/type/base/json_file_spec.rb b/spec/type/base/json_file_spec.rb new file mode 100644 index 00000000..1fbdd9c8 --- /dev/null +++ b/spec/type/base/json_file_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +set :os, {:family => 'base'} + +describe json_file('example.json') do + let(:stdout) {< include('title' => 'this is a json')) } + its(:content) { should include('json' => include('array' => include('title' => 'array 2'))) } +end +