diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-07-07 00:05:09 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-07-15 11:16:12 -0700 |
| commit | 8c4cc7cae65b43fc4ab2f56ec27ee05a9bfc0494 (patch) | |
| tree | ceea5e1474aa56787264128572d6bf06d446d78e | |
| parent | 7e5ca648112a2703ba827f96f36fe2a5f7d1c751 (diff) | |
| download | puppet-8c4cc7cae65b43fc4ab2f56ec27ee05a9bfc0494.tar.gz puppet-8c4cc7cae65b43fc4ab2f56ec27ee05a9bfc0494.tar.xz puppet-8c4cc7cae65b43fc4ab2f56ec27ee05a9bfc0494.zip | |
Switching to use of json matchers
This is only in the Node and Indirection::Request code.
It makes the tests much simpler.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Reviewed-by: Nick Lewis <nick@puppetlabs.com>
| -rwxr-xr-x | spec/unit/indirector/request_spec.rb | 16 | ||||
| -rwxr-xr-x | spec/unit/node_spec.rb | 20 |
2 files changed, 16 insertions, 20 deletions
diff --git a/spec/unit/indirector/request_spec.rb b/spec/unit/indirector/request_spec.rb index 152fe5871..450cad2ed 100755 --- a/spec/unit/indirector/request_spec.rb +++ b/spec/unit/indirector/request_spec.rb @@ -308,28 +308,24 @@ describe Puppet::Indirector::Request do end it "should produce a hash with the document_type set to 'request'" do - PSON.parse(@request.to_pson)["document_type"].should == "Puppet::Indirector::Request" - end - - it "should add its data under the 'data' attribute in the hash" do - PSON.parse(@request.to_pson)["data"].should be_instance_of(Hash) + @request.should set_json_document_type_to("Puppet::Indirector::Request") end it "should set the 'key'" do - PSON.parse(@request.to_pson)["data"]['key'].should == "foo" + @request.should set_json_attribute("key").to("foo") end it "should include an attribute for its indirection name" do - PSON.parse(@request.to_pson)["data"]['type'].should == "facts" + @request.should set_json_attribute("type").to("facts") end it "should include a 'method' attribute set to its method" do - PSON.parse(@request.to_pson)["data"]['method'].should == "find" + @request.should set_json_attribute("method").to("find") end it "should add all attributes under the 'attributes' attribute" do @request.ip = "127.0.0.1" - PSON.parse(@request.to_pson)["data"]['attributes']['ip'].should == "127.0.0.1" + @request.should set_json_attribute("attributes", "ip").to("127.0.0.1") end it "should add all options under the 'attributes' attribute" do @@ -340,7 +336,7 @@ describe Puppet::Indirector::Request do it "should include the instance if provided" do facts = Puppet::Node::Facts.new("foo") @request.instance = facts - PSON.parse(@request.to_pson)["data"]['instance'].should be_instance_of(Puppet::Node::Facts) + PSON.parse(@request.to_pson)["data"]['instance'].should be_instance_of(Hash) end end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index ae71046f0..a6ae67aeb 100755 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -43,30 +43,30 @@ describe Puppet::Node do end it "should provide its name" do - PSON.parse(@node.to_pson)['data']['name'].should == "mynode" + @node.should set_json_attribute('name').to("mynode") end it "should include the classes if set" do @node.classes = %w{a b c} - PSON.parse(@node.to_pson)['data']['classes'].should == %w{a b c} + @node.should set_json_attribute("classes").to(%w{a b c}) end it "should not include the classes if there are none" do - PSON.parse(@node.to_pson)['data'].should_not be_include('classes') + @node.should_not set_json_attribute('classes') end it "should include parameters if set" do @node.parameters = {"a" => "b", "c" => "d"} - PSON.parse(@node.to_pson)['data']['parameters'].should == {"a" => "b", "c" => "d"} + @node.should set_json_attribute('parameters').to({"a" => "b", "c" => "d"}) end it "should not include the parameters if there are none" do - PSON.parse(@node.to_pson)['data'].should_not be_include('parameters') + @node.should_not set_json_attribute('parameters') end it "should include the environment" do @node.environment = "production" - PSON.parse(@node.to_pson)['data']['environment'].should == "production" + @node.should set_json_attribute('environment').to('production') end end @@ -81,22 +81,22 @@ describe Puppet::Node do end it "should set its name" do - from_json(@node.to_pson).name.should == "mynode" + Puppet::Node.should read_json_attribute('name').from(@node.to_pson).as("mynode") end it "should include the classes if set" do @node.classes = %w{a b c} - from_json(@node.to_pson).classes.should == %w{a b c} + Puppet::Node.should read_json_attribute('classes').from(@node.to_pson).as(%w{a b c}) end it "should include parameters if set" do @node.parameters = {"a" => "b", "c" => "d"} - from_json(@node.to_pson).parameters.should == {"a" => "b", "c" => "d"} + Puppet::Node.should read_json_attribute('parameters').from(@node.to_pson).as({"a" => "b", "c" => "d"}) end it "should include the environment" do @node.environment = "production" - from_json(@node.to_pson).environment.name.should == :production + Puppet::Node.should read_json_attribute('environment').from(@node.to_pson).as(Puppet::Node::Environment.new(:production)) end end end |
