diff options
| author | Markus Roberts <Markus@reality.com> | 2010-03-25 15:54:33 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 33b565a0d76b07f354e2e145e7e03e5a5db69e48 (patch) | |
| tree | 934f60c39eb6f4a9cf9c468552bbaea2cd8787f6 /spec | |
| parent | 4820a1b569444f942b3ceb6ee3a0832ed6faf613 (diff) | |
| download | puppet-33b565a0d76b07f354e2e145e7e03e5a5db69e48.tar.gz puppet-33b565a0d76b07f354e2e145e7e03e5a5db69e48.tar.xz puppet-33b565a0d76b07f354e2e145e7e03e5a5db69e48.zip | |
Fix for #3424 and tests to prove it.
The original pure ruby yaml patch missed some edge cases; specifically, classes
that were modified by the syck version to directly call it and thus never
reached the pure ruby version. This adds monkey patches to all of those case
which we might reasonably care about (omitting, for example, calls within the
syck version to itself) and tests which show that the monkey patch works.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/util/zaml.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/spec/unit/util/zaml.rb b/spec/unit/util/zaml.rb new file mode 100644 index 000000000..1f21c4e29 --- /dev/null +++ b/spec/unit/util/zaml.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +require 'puppet/util/monkey_patches' + +describe "Pure ruby yaml implementation" do + { + 7 => "--- 7", + 3.14159 => "--- 3.14159", + 'test' => "--- test", + [] => "--- []", + :symbol => "--- !ruby/sym symbol", + {:a => "A"} => "--- \n !ruby/sym a: A" + }.each { |o,y| + it "should convert the #{o.class} #{o.inspect} to yaml" do + o.to_yaml.should == y + end + it "should produce yaml for the #{o.class} #{o.inspect} that can be reconstituted" do + YAML.load(o.to_yaml).should == o + end + } + # + # Can't test for equality on raw objects + { + Object.new => "--- !ruby/object {}", + [Object.new] => "--- \n - !ruby/object {}", + {Object.new => Object.new} => "--- \n ? !ruby/object {}\n : !ruby/object {}" + }.each { |o,y| + it "should convert the #{o.class} #{o.inspect} to yaml" do + o.to_yaml.should == y + end + it "should produce yaml for the #{o.class} #{o.inspect} that can be reconstituted" do + lambda { YAML.load(o.to_yaml) }.should_not raise_error + end + } +end + |
