summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlamont-granquist <lamont@scriptkiddie.org>2014-08-13 11:29:49 -0700
committerlamont-granquist <lamont@scriptkiddie.org>2014-08-13 11:29:49 -0700
commit4f6c1fa1fab67e9aef46af0fe920acdff613d966 (patch)
treea3bca6e637d58204d8c7df0ab332566deba27001
parent9e0a614d6251d31a08c48c98b1699dadca221acd (diff)
parentc33e9c16655b5fb18e71bfcee5c32edc29856f78 (diff)
downloadchef-4f6c1fa1fab67e9aef46af0fe920acdff613d966.tar.gz
Merge pull request #1810 from opscode/lcg/json-comment-tests
Lcg/json comment tests
-rw-r--r--spec/data/object_loader/environments/test.json2
-rw-r--r--spec/data/object_loader/environments/test_json_class.json2
-rw-r--r--spec/data/object_loader/nodes/test.json2
-rw-r--r--spec/data/object_loader/nodes/test_json_class.json2
-rw-r--r--spec/data/object_loader/roles/test.json2
-rw-r--r--spec/data/object_loader/roles/test_json_class.json2
-rw-r--r--spec/unit/json_compat_spec.rb18
7 files changed, 29 insertions, 1 deletions
diff --git a/spec/data/object_loader/environments/test.json b/spec/data/object_loader/environments/test.json
index cb4c790e44..744819c60a 100644
--- a/spec/data/object_loader/environments/test.json
+++ b/spec/data/object_loader/environments/test.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"description": "prod",
"run_list": []
diff --git a/spec/data/object_loader/environments/test_json_class.json b/spec/data/object_loader/environments/test_json_class.json
index 28345198c9..f51943f60e 100644
--- a/spec/data/object_loader/environments/test_json_class.json
+++ b/spec/data/object_loader/environments/test_json_class.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"json_class": "Chef::Environment",
"description": "prod",
diff --git a/spec/data/object_loader/nodes/test.json b/spec/data/object_loader/nodes/test.json
index 49f297d039..a370d6378d 100644
--- a/spec/data/object_loader/nodes/test.json
+++ b/spec/data/object_loader/nodes/test.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"environment": "prod",
"run_list": []
diff --git a/spec/data/object_loader/nodes/test_json_class.json b/spec/data/object_loader/nodes/test_json_class.json
index f485ae8748..3c5b12ce6c 100644
--- a/spec/data/object_loader/nodes/test_json_class.json
+++ b/spec/data/object_loader/nodes/test_json_class.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"json_class": "Chef::Node",
"environment": "prod",
diff --git a/spec/data/object_loader/roles/test.json b/spec/data/object_loader/roles/test.json
index cb4c790e44..744819c60a 100644
--- a/spec/data/object_loader/roles/test.json
+++ b/spec/data/object_loader/roles/test.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"description": "prod",
"run_list": []
diff --git a/spec/data/object_loader/roles/test_json_class.json b/spec/data/object_loader/roles/test_json_class.json
index ce922f592d..f975c8be43 100644
--- a/spec/data/object_loader/roles/test_json_class.json
+++ b/spec/data/object_loader/roles/test_json_class.json
@@ -1,4 +1,6 @@
{
+ /* testing that we support c-style comments */
+ // testing that we support c++-style comments as well
"name": "test",
"json_class": "Chef::Role",
"description": "prod",
diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb
index 6d262734fd..e355a47faa 100644
--- a/spec/unit/json_compat_spec.rb
+++ b/spec/unit/json_compat_spec.rb
@@ -21,7 +21,7 @@ require 'chef/json_compat'
describe Chef::JSONCompat do
- describe "with JSON containing an existing class" do
+ describe "#from_json with JSON containing an existing class" do
let(:json) { '{"json_class": "Chef::Role"}' }
it "returns an instance of the class instead of a Hash" do
@@ -29,6 +29,22 @@ describe Chef::JSONCompat do
end
end
+ describe "#from_json with JSON containing comments" do
+ let(:json) { %Q{{\n/* comment */\n// comment 2\n"json_class": "Chef::Role"}} }
+
+ it "returns an instance of the class instead of a Hash" do
+ expect(Chef::JSONCompat.from_json(json).class).to eq Chef::Role
+ end
+ end
+
+ describe "#parse with JSON containing comments" do
+ let(:json) { %Q{{\n/* comment */\n// comment 2\n"json_class": "Chef::Role"}} }
+
+ it "returns a Hash" do
+ expect(Chef::JSONCompat.parse(json).class).to eq Hash
+ end
+ end
+
describe 'with JSON containing "Chef::Sandbox" as a json_class value' do
require 'chef/sandbox' # Only needed for this test