diff options
| author | Luke Kanies <luke@puppetlabs.com> | 2011-04-12 23:54:08 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@puppetlabs.com> | 2011-04-14 17:07:39 -0700 |
| commit | e424740d78b8b72dc6bd7ebbbe27b237347d67f5 (patch) | |
| tree | 9f2afddc64f32990f298689e327ac05fcb2b4719 /spec/unit/node_spec.rb | |
| parent | f37b2e106ed171042c94a1a0b8fd31a254a69588 (diff) | |
| download | puppet-e424740d78b8b72dc6bd7ebbbe27b237347d67f5.tar.gz puppet-e424740d78b8b72dc6bd7ebbbe27b237347d67f5.tar.xz puppet-e424740d78b8b72dc6bd7ebbbe27b237347d67f5.zip | |
Adding json-specific matchers
These make the JSON tests much easier to read and
write. They're the first custom matchers that I can
find, so they're breaking a bit of new ground,
but the JSON tests were pretty hard to read
and there was a lot of duplication, so it seemed
worth it.
Note that for some reason they're not working on
Facts - it seems to get immediately turned into
a full instance by the JSON parsing subsystem,
and I've no idea why.
Reviewed-by: Daniel Pittman <daniel@puppetlabs.com>
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/unit/node_spec.rb')
| -rwxr-xr-x | spec/unit/node_spec.rb | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index af3110f45..e8f826dca 100755 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -1,5 +1,6 @@ #!/usr/bin/env rspec require 'spec_helper' +require 'matchers/json' describe Puppet::Node do describe "when managing its environment" do @@ -42,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 @@ -80,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 |
