diff options
Diffstat (limited to 'chef/spec')
22 files changed, 37 insertions, 34 deletions
diff --git a/chef/spec/functional/tiny_server_spec.rb b/chef/spec/functional/tiny_server_spec.rb index 59a5f16501..370698f0c7 100644 --- a/chef/spec/functional/tiny_server_spec.rb +++ b/chef/spec/functional/tiny_server_spec.rb @@ -54,7 +54,7 @@ describe TinyServer::API do response[0].should == 404 response[1].should == {'Content-Type' => 'application/json'} response[2].should be_a_kind_of(String) - response_obj = JSON.parse(response[2]) + response_obj = Chef::JSON.from_json(response[2]) response_obj["message"].should == "no data matches the request for /no_such_thing" response_obj["available_routes"].should == {"GET"=>[], "PUT"=>[], "POST"=>[], "DELETE"=>[]} response_obj["request"].should == {"REQUEST_METHOD"=>"GET", "REQUEST_URI"=>"/no_such_thing"} diff --git a/chef/spec/lib/chef/resource/zen_master.rb b/chef/spec/lib/chef/resource/zen_master.rb index b3c2c7712a..2ecacd3f6a 100644 --- a/chef/spec/lib/chef/resource/zen_master.rb +++ b/chef/spec/lib/chef/resource/zen_master.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +16,9 @@ # limitations under the License. # +require 'chef/knife' +require 'chef/json' + class Chef class Resource class ZenMaster < Chef::Resource diff --git a/chef/spec/tiny_server.rb b/chef/spec/tiny_server.rb index 99b2887251..18b593ec8e 100644 --- a/chef/spec/tiny_server.rb +++ b/chef/spec/tiny_server.rb @@ -20,7 +20,7 @@ require 'rubygems' require 'rack' require 'thin' require 'singleton' -require 'json' +require 'chef/json' require 'open-uri' module TinyServer diff --git a/chef/spec/unit/api_client_spec.rb b/chef/spec/unit/api_client_spec.rb index 4b73d80575..eba41310c4 100644 --- a/chef/spec/unit/api_client_spec.rb +++ b/chef/spec/unit/api_client_spec.rb @@ -157,7 +157,7 @@ describe Chef::ApiClient do @client.public_key("crowes") @client.private_key("monkeypants") @client.admin(true) - @deserial = JSON.parse(@client.to_json) + @deserial = Chef::JSON.from_json(@client.to_json) end it "should deserialize to a Chef::ApiClient object" do diff --git a/chef/spec/unit/application/client_spec.rb b/chef/spec/unit/application/client_spec.rb index e92b2458ef..d5daec07d4 100644 --- a/chef/spec/unit/application/client_spec.rb +++ b/chef/spec/unit/application/client_spec.rb @@ -99,7 +99,7 @@ describe Chef::Application::Client, "reconfigure" do end it "should parse the json out of the file" do - JSON.should_receive(:parse).with(@json.read) + Chef::JSON.should_receive(:from_json).with(@json.read) @app.reconfigure end end @@ -109,7 +109,7 @@ describe Chef::Application::Client, "reconfigure" do Chef::Config[:json_attribs] = "/etc/chef/dna.json" @json = mock("Tempfile", :read => {:a=>"b"}.to_json, :null_object => true) @app.stub!(:open).with("/etc/chef/dna.json").and_return(@json) - JSON.stub!(:parse).with(@json.read).and_raise(JSON::ParserError) + Chef::JSON.stub!(:from_json).with(@json.read).and_raise(JSON::ParserError) Chef::Application.stub!(:fatal!).and_return(true) end diff --git a/chef/spec/unit/application/solo_spec.rb b/chef/spec/unit/application/solo_spec.rb index 2a95174147..2ec1d3be4d 100644 --- a/chef/spec/unit/application/solo_spec.rb +++ b/chef/spec/unit/application/solo_spec.rb @@ -87,7 +87,7 @@ describe Chef::Application::Solo do end it "should parse the json out of the file" do - JSON.should_receive(:parse).with(@json.read) + Chef::JSON.should_receive(:from_json).with(@json.read) @app.reconfigure end end @@ -97,7 +97,7 @@ describe Chef::Application::Solo do Chef::Config[:json_attribs] = "/etc/chef/dna.json" @json = mock("Tempfile", :read => {:a=>"b"}.to_json, :null_object => true) @app.stub!(:open).with("/etc/chef/dna.json").and_return(@json) - JSON.stub!(:parse).with(@json.read).and_raise(JSON::ParserError) + Chef::JSON.stub!(:from_json).with(@json.read).and_raise(JSON::ParserError) Chef::Application.stub!(:fatal!).and_return(true) end diff --git a/chef/spec/unit/checksum_spec.rb b/chef/spec/unit/checksum_spec.rb index d2740dae64..c8b405194f 100644 --- a/chef/spec/unit/checksum_spec.rb +++ b/chef/spec/unit/checksum_spec.rb @@ -92,7 +92,7 @@ describe Chef::Checksum do describe "when converted to json" do before do @checksum_as_json = @checksum.to_json - @checksum_as_hash_from_json = JSON.parse(@checksum_as_json, :create_additions => false) + @checksum_as_hash_from_json = Chef::JSON.from_json(@checksum_as_json, :create_additions => false) end it "contains the file's MD5 checksum" do diff --git a/chef/spec/unit/cookbook/metadata_spec.rb b/chef/spec/unit/cookbook/metadata_spec.rb index 9da3b0f84f..4b8420b149 100644 --- a/chef/spec/unit/cookbook/metadata_spec.rb +++ b/chef/spec/unit/cookbook/metadata_spec.rb @@ -515,11 +515,11 @@ describe Chef::Cookbook::Metadata do describe "serialize" do before(:each) do - @serial = JSON.parse(@meta.to_json) + @serial = Chef::JSON.from_json(@meta.to_json) end it "should serialize to a json hash" do - JSON.parse(@meta.to_json).should be_a_kind_of(Hash) + Chef::JSON.from_json(@meta.to_json).should be_a_kind_of(Hash) end %w{ diff --git a/chef/spec/unit/data_bag_item_spec.rb b/chef/spec/unit/data_bag_item_spec.rb index 661e2e7904..c13cca4abf 100644 --- a/chef/spec/unit/data_bag_item_spec.rb +++ b/chef/spec/unit/data_bag_item_spec.rb @@ -145,7 +145,7 @@ describe Chef::DataBagItem do before(:each) do @data_bag_item.data_bag('mars_volta') @data_bag_item.raw_data = { "id" => "octahedron", "snooze" => { "finally" => :world_will }} - @deserial = JSON.parse(@data_bag_item.to_json) + @deserial = Chef::JSON.from_json(@data_bag_item.to_json) end it "should deserialize to a Chef::DataBagItem object" do diff --git a/chef/spec/unit/data_bag_spec.rb b/chef/spec/unit/data_bag_spec.rb index 1f140b5f88..da8c792ea0 100644 --- a/chef/spec/unit/data_bag_spec.rb +++ b/chef/spec/unit/data_bag_spec.rb @@ -52,7 +52,7 @@ describe Chef::DataBag do describe "deserialize" do before(:each) do @data_bag.name('mars_volta') - @deserial = JSON.parse(@data_bag.to_json) + @deserial = Chef::JSON.from_json(@data_bag.to_json) end it "should deserialize to a Chef::DataBag object" do diff --git a/chef/spec/unit/handler/json_file_spec.rb b/chef/spec/unit/handler/json_file_spec.rb index 7a1c112360..6d3de0b970 100644 --- a/chef/spec/unit/handler/json_file_spec.rb +++ b/chef/spec/unit/handler/json_file_spec.rb @@ -52,7 +52,7 @@ describe Chef::Handler::JsonFile do it "saves run status data to a file as JSON" do @handler.should_receive(:build_report_dir) @handler.run_report_unsafe(@run_status) - reported_data = JSON.parse(@file_mock.string) + reported_data = Chef::JSON.from_json(@file_mock.string) reported_data['exception'].should == "Exception: Boy howdy!" reported_data['start_time'].should == @expected_time.iso8601 reported_data['end_time'].should == (@expected_time + 5).iso8601 diff --git a/chef/spec/unit/index_queue_spec.rb b/chef/spec/unit/index_queue_spec.rb index 02cdd514e3..61382fb8ec 100644 --- a/chef/spec/unit/index_queue_spec.rb +++ b/chef/spec/unit/index_queue_spec.rb @@ -113,7 +113,7 @@ describe Chef::IndexQueue::Indexable do @queue = FauxQueue.new @publisher.should_receive(:queue_for_object).with("0000000-1111-2222-3333-444444444444").and_yield(@queue) @indexable_obj.add_to_index(:database => "couchdb@localhost,etc.", :id=>"0000000-1111-2222-3333-444444444444") - published_message = JSON.parse(@queue.published_message) + published_message = Chef::JSON.from_json(@queue.published_message) published_message.should == {"action" => "add", "payload" => {"item" => @item_as_hash, "type" => "indexable_test_harness", "database" => "couchdb@localhost,etc.", @@ -126,7 +126,7 @@ describe Chef::IndexQueue::Indexable do @publisher.should_receive(:queue_for_object).with("0000000-1111-2222-3333-444444444444").and_yield(@queue) @indexable_obj.delete_from_index(:database => "couchdb2@localhost", :id=>"0000000-1111-2222-3333-444444444444") - published_message = JSON.parse(@queue.published_message) + published_message = Chef::JSON.from_json(@queue.published_message) published_message.should == {"action" => "delete", "payload" => { "item" => @item_as_hash, "type" => "indexable_test_harness", "database" => "couchdb2@localhost", diff --git a/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb b/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb index b3930689ef..9bee41facc 100644 --- a/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb +++ b/chef/spec/unit/knife/cookbook_metadata_from_file_spec.rb @@ -27,7 +27,7 @@ describe Chef::Knife::CookbookMetadataFromFile do @tgt = File.expand_path(File.join(CHEF_SPEC_DATA, "metadata", "quick_start", "metadata.json")) @knife = Chef::Knife::CookbookMetadataFromFile.new @knife.name_args = [ @src ] - @knife.stub!(:json_pretty_generate).and_return(true) + @knife.stub!(:to_json_pretty).and_return(true) @md = Chef::Cookbook::Metadata.new Chef::Cookbook::Metadata.stub(:new).and_return(@md) end @@ -56,7 +56,7 @@ describe Chef::Knife::CookbookMetadataFromFile do end it "should generate json from the metadata" do - JSON.should_receive(:pretty_generate).with(@md) + Chef::JSON.should_receive(:to_json_pretty).with(@md) @knife.run end diff --git a/chef/spec/unit/knife/data_bag_show_spec.rb b/chef/spec/unit/knife/data_bag_show_spec.rb index f72cae1987..1c4066991a 100644 --- a/chef/spec/unit/knife/data_bag_show_spec.rb +++ b/chef/spec/unit/knife/data_bag_show_spec.rb @@ -50,7 +50,7 @@ describe Chef::Knife::DataBagShow do Chef::DataBagItem.should_receive(:load).with('bag_o_data', 'an_item').and_return(data_item_content) @knife.run - JSON.parse(@stdout.string).should == data_item_content + Chef::JSON.from_json(@stdout.string).should == data_item_content end end diff --git a/chef/spec/unit/mixin/deprecation_spec.rb b/chef/spec/unit/mixin/deprecation_spec.rb index af0b27ed22..b78080971b 100644 --- a/chef/spec/unit/mixin/deprecation_spec.rb +++ b/chef/spec/unit/mixin/deprecation_spec.rb @@ -31,4 +31,4 @@ describe Chef::Mixin::Deprecation::DeprecatedInstanceVariable do @deprecated_ivar.to_sym.should == :value end -end
\ No newline at end of file +end diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb index 469720706c..8e896073ac 100644 --- a/chef/spec/unit/node_spec.rb +++ b/chef/spec/unit/node_spec.rb @@ -487,7 +487,7 @@ describe Chef::Node do describe "json" do it "should serialize itself as json" do @node.find_file("test.example.com") - json = @node.to_json() + json = Chef::JSON.to_json(@node) json.should =~ /json_class/ json.should =~ /name/ json.should =~ /normal/ @@ -498,8 +498,8 @@ describe Chef::Node do it "should deserialize itself from json" do @node.find_file("test.example.com") - json = @node.to_json - serialized_node = JSON.parse(json) + json = Chef::JSON.to_json(@node) + serialized_node = Chef::JSON.from_json(json) serialized_node.should be_a_kind_of(Chef::Node) serialized_node.name.should eql(@node.name) @node.each_attribute do |k,v| diff --git a/chef/spec/unit/openid_registration_spec.rb b/chef/spec/unit/openid_registration_spec.rb index 5187ee0d21..5f8421e9f7 100644 --- a/chef/spec/unit/openid_registration_spec.rb +++ b/chef/spec/unit/openid_registration_spec.rb @@ -56,7 +56,7 @@ describe Chef::OpenIDRegistration, "from_json" do oreg.name = "foobar" oreg.set_password("monkey") oreg_json = oreg.to_json - nreg = JSON.parse(oreg_json) + nreg = Chef::JSON.from_json(oreg_json) nreg.should be_a_kind_of(Chef::OpenIDRegistration) %w{name salt password validated}.each do |verify| nreg.send(verify.to_sym).should eql(oreg.send(verify.to_sym)) diff --git a/chef/spec/unit/resource_collection_spec.rb b/chef/spec/unit/resource_collection_spec.rb index e9ee2f86a8..578e5e8908 100644 --- a/chef/spec/unit/resource_collection_spec.rb +++ b/chef/spec/unit/resource_collection_spec.rb @@ -222,7 +222,7 @@ describe Chef::ResourceCollection do it "should deserialize itself from json" do @rc << @resource json = @rc.to_json - s_rc = JSON.parse(json) + s_rc = Chef::JSON.from_json(json) s_rc.should be_a_kind_of(Chef::ResourceCollection) s_rc[0].name.should eql(@resource.name) end diff --git a/chef/spec/unit/resource_spec.rb b/chef/spec/unit/resource_spec.rb index 72be22fa04..fdb3816788 100644 --- a/chef/spec/unit/resource_spec.rb +++ b/chef/spec/unit/resource_spec.rb @@ -204,7 +204,7 @@ describe Chef::Resource do describe "self.json_create" do it "should deserialize itself from json" do json = @resource.to_json - serialized_node = JSON.parse(json) + serialized_node = Chef::JSON.from_json(json) serialized_node.should be_a_kind_of(Chef::Resource) serialized_node.name.should eql(@resource.name) end diff --git a/chef/spec/unit/rest_spec.rb b/chef/spec/unit/rest_spec.rb index a2a697181b..1a79ea8075 100644 --- a/chef/spec/unit/rest_spec.rb +++ b/chef/spec/unit/rest_spec.rb @@ -204,7 +204,7 @@ describe Chef::REST do it "should inflate the body as to an object if JSON is returned" do @http_response.add_field("content-type", "application/json") - JSON.should_receive(:parse).with("ninja").and_return("ohai2u_success") + Chef::JSON.should_receive(:from_json).with("ninja").and_return("ohai2u_success") @rest.run_request(:GET, @url, {}).should == "ohai2u_success" end diff --git a/chef/spec/unit/role_spec.rb b/chef/spec/unit/role_spec.rb index 548faaac7c..fbb0b3c40a 100644 --- a/chef/spec/unit/role_spec.rb +++ b/chef/spec/unit/role_spec.rb @@ -115,11 +115,11 @@ describe Chef::Role do @role.run_list('one', 'two', 'role[a]') @role.default_attributes({ :el_groupo => 'nuevo' }) @role.override_attributes({ :deloused => 'in the comatorium' }) - @serial = @role.to_json + @serial = Chef::JSON.to_json(@role) end it "should serialize to a json hash" do - @role.to_json.should match(/^\{.+\}$/) + Chef::JSON.to_json(@role).should match(/^\{.+\}$/) end %w{ @@ -151,7 +151,7 @@ describe Chef::Role do @role.run_list('one', 'two', 'role[a]') @role.default_attributes({ 'el_groupo' => 'nuevo' }) @role.override_attributes({ 'deloused' => 'in the comatorium' }) - @deserial = JSON.parse(@role.to_json) + @deserial = Chef::JSON.from_json(Chef::JSON.to_json(@role)) end it "should deserialize to a Chef::Role object" do diff --git a/chef/spec/unit/webui_user_spec.rb b/chef/spec/unit/webui_user_spec.rb index 0e1c053013..4db9294b4e 100644 --- a/chef/spec/unit/webui_user_spec.rb +++ b/chef/spec/unit/webui_user_spec.rb @@ -217,8 +217,8 @@ describe Chef::WebUIUser do end it "sets its couchdb id when loading from the database" do - # reqs via REST eventually get to JSON.parse - webui_user = JSON.parse('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID"}') + # reqs via REST eventually get to Chef::JSON.from_json + webui_user = Chef::JSON.from_json('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID"}') webui_user.couchdb_id.should == "IdontNeedNoID" end @@ -230,9 +230,9 @@ describe Chef::WebUIUser do end it "sets the couchdb_rev when loading from the database" do - webui_user = JSON.parse('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID","_rev":"moto"}') + webui_user = Chef::JSON.from_json('{"salt":null,"name":"test_user","json_class":"Chef::WebUIUser","admin":false,"openid":null,"password":null,"chef_type":"webui_user","_id":"IdontNeedNoID","_rev":"moto"}') webui_user.couchdb_rev.should == "moto" end end -end
\ No newline at end of file +end |