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 | |
| 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')
| -rwxr-xr-x | spec/unit/node/facts_spec.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/spec/unit/node/facts_spec.rb b/spec/unit/node/facts_spec.rb index 3c7c9d08b..0a5948cfa 100755 --- a/spec/unit/node/facts_spec.rb +++ b/spec/unit/node/facts_spec.rb @@ -1,6 +1,6 @@ #!/usr/bin/env rspec require 'spec_helper' - +require 'matchers/json' require 'puppet/node/facts' describe Puppet::Node::Facts, "when indirecting" do @@ -126,14 +126,17 @@ describe Puppet::Node::Facts, "when indirecting" do Time.stubs(:now).returns(@timestamp) facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3}) facts.expiration = @expiration - pson = PSON.parse(facts.to_pson) - pson.should == {"name"=>"foo", "timestamp"=>@timestamp.to_s, "expiration"=>@expiration.to_s, "values"=>{"a"=>1, "b"=>2, "c"=>3}} + facts.to_pson.should == %Q[{"data":{"name":"foo","timestamp":"Thu Oct 28 11:16:31 -0700 2010","expiration":"Thu Oct 28 11:21:31 -0700 2010","values":{"a":1,"b":2,"c":3}},"document_type":"Puppet::Node::Facts"}] end it "should not include nil values" do facts = Puppet::Node::Facts.new("foo", {'a' => 1, 'b' => 2, 'c' => 3}) - pson = PSON.parse(facts.to_pson) - pson.should_not be_include("expiration") + + # XXX:LAK For some reason this is resurrection the full instance, instead + # of just returning the hash. This code works, but I can't figure out what's + # going on. + newfacts = PSON.parse(facts.to_pson) + newfacts.expiration.should be_nil end it "should be able to handle nil values" do |
