+1, although please make sure you have 4 space indentation everywhere; it looks like there are a couple of whitespace issues.
On Jul 25, 2009, at 2:45 PM, Markus wrote: > > From: MarkusQ <[email protected]> > > Ticket 2444 actually represents two issues; firstly that the json > tests were written in a way that assumed serialization ordering of > hash elements, and thus would sporadically fail, and secondly that > this failure was masking an actual problem with the json routines. > > This patch fixes the ordering assumprion by wrapping the serialized > representations with a function to enforce a canonical order prior > to comparison. > > Signed-off-by: MarkusQ <[email protected]> > --- > spec/integration/network/formats.rb | 18 +++++++++++++++--- > 1 files changed, 15 insertions(+), 3 deletions(-) > > diff --git a/spec/integration/network/formats.rb b/spec/integration/ > network/formats.rb > index c3b97bc..77a972b 100755 > --- a/spec/integration/network/formats.rb > +++ b/spec/integration/network/formats.rb > @@ -7,7 +7,7 @@ require 'puppet/network/formats' > class JsonIntTest > attr_accessor :string > def ==(other) > - string == other.string > + string == (other.respond_to? :string) ? other.string : > other.inspect > end > > def self.from_json(data) > @@ -24,6 +24,11 @@ class JsonIntTest > 'data' => [...@string] > }.to_json(*args) > end > + > + def self.canonical_order(s) > + s.gsub(/\{"data":\[(.*?) > \],"json_class":"JsonIntTest"\}/,'{"json_class":"JsonIntTest","data": > [\1]}') > + end > + > end > > describe Puppet::Network::FormatHandler.format(:s) do > @@ -58,15 +63,22 @@ describe > Puppet::Network::FormatHandler.format(:json) do > > it "should be able to render an instance to json" do > instance = JsonIntTest.new("foo") > + > JsonIntTest.canonical_order(@json.render(instance)).should == > JsonIntTest.canonical_order('{"json_class":"JsonIntTest","data": > ["foo"]}' ) > + end > + > + it "should be able to render arrays to json" do > + @json.render([1,2]).should == '[1,2]' > + end > > - @json.render(instance).should == > '{"json_class":"JsonIntTest","data":["foo"]}' > + it "should be able to render arrays containing hashes to > json" do > + @json.render([{"one"=>1},{"two"=>2}]).should == > '[{"one":1},{"two":2}]' > end > > it "should be able to render multiple instances to json" do > one = JsonIntTest.new("one") > two = JsonIntTest.new("two") > > - @json.render([one, two]).should == > '[{"json_class":"JsonIntTest","data":["one"]}, > {"json_class":"JsonIntTest","data":["two"]}]' > + > JsonIntTest.canonical_order(@json.render([one,two])).should == > JsonIntTest.canonical_order('[{"json_class":"JsonIntTest","data": > ["one"]},{"json_class":"JsonIntTest","data":["two"]}]') > end > > it "should be able to intern json into an instance" do > -- > 1.6.0.4 > > > > -- Learning is not attained by chance, it must be sought for with ardor and attended to with diligence. -- Abigail Adams --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
