spec/unit/network/formats_spec.rb in puppet-2.7.26 vs spec/unit/network/formats_spec.rb in puppet-3.0.0.rc4
- old
+ new
@@ -1,6 +1,6 @@
-#!/usr/bin/env rspec
+#! /usr/bin/env ruby -S rspec
require 'spec_helper'
require 'puppet/network/formats'
class PsonTest
@@ -53,34 +53,21 @@
instances = [mock('instance')]
instances.expects(:to_yaml).returns "foo"
@yaml.render_multiple(instances).should == "foo"
end
- it "should deserialize YAML" do
- @yaml.intern(String, YAML.dump("foo")).should == "foo"
+ it "should intern by calling 'YAML.load'" do
+ text = "foo"
+ YAML.expects(:load).with("foo").returns "bar"
+ @yaml.intern(String, text).should == "bar"
end
- it "should deserialize symbols as strings" do
- @yaml.intern(String, YAML.dump(:foo)).should == "foo"
+ it "should intern multiples by calling 'YAML.load'" do
+ text = "foo"
+ YAML.expects(:load).with("foo").returns "bar"
+ @yaml.intern_multiple(String, text).should == "bar"
end
-
- it "should fail when type does not match deserialized form and has no from_pson" do
- expect do
- @yaml.intern(Hash, YAML.dump("foo"))
- end.to raise_error(NoMethodError)
- end
-
- it "should load from yaml when deserializing an array" do
- text = YAML.dump(["foo"])
- @yaml.intern_multiple(String, text).should == ["foo"]
- end
-
- it "should fail when one element does not have a from_pson" do
- expect do
- @yaml.intern_multiple(Hash, YAML.dump(["foo"]))
- end.to raise_error(NoMethodError)
- end
end
describe "base64 compressed yaml", :if => Puppet.features.zlib? do
yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml)
@@ -119,29 +106,33 @@
@yaml.expects(:encode).with("foo").returns "bar"
@yaml.render(instances).should == "bar"
end
- it "should round trip data" do
- @yaml.intern(String, @yaml.encode("foo")).should == "foo"
+ it "should intern by calling decode" do
+ text = "foo"
+ @yaml.expects(:decode).with("foo").returns "bar"
+ @yaml.intern(String, text).should == "bar"
end
- it "should round trip multiple data elements" do
- data = @yaml.render_multiple(["foo", "bar"])
- @yaml.intern_multiple(String, data).should == ["foo", "bar"]
+ it "should intern multiples by calling 'decode'" do
+ text = "foo"
+ @yaml.expects(:decode).with("foo").returns "bar"
+ @yaml.intern_multiple(String, text).should == "bar"
end
- it "should intern by base64 decoding, uncompressing and safely Yaml loading" do
- input = Base64.encode64(Zlib::Deflate.deflate(YAML.dump("data in")))
-
- @yaml.intern(String, input).should == "data in"
+ it "should decode by base64 decoding, uncompressing and Yaml loading" do
+ Base64.expects(:decode64).with("zorg").returns "foo"
+ Zlib::Inflate.expects(:inflate).with("foo").returns "baz"
+ YAML.expects(:load).with("baz").returns "bar"
+ @yaml.decode("zorg").should == "bar"
end
- it "should render by compressing and base64 encoding" do
- output = @yaml.render("foo")
-
- YAML.load(Zlib::Inflate.inflate(Base64.decode64(output))).should == "foo"
+ it "should encode by compressing and base64 encoding" do
+ Zlib::Deflate.expects(:deflate).with("foo", Zlib::BEST_COMPRESSION).returns "bar"
+ Base64.expects(:encode64).with("bar").returns "baz"
+ @yaml.encode("foo").should == "baz"
end
describe "when zlib is disabled" do
before do
Puppet[:zlib] = false
@@ -150,14 +141,14 @@
it "use_zlib? should return false" do
@yaml.use_zlib?.should == false
end
it "should refuse to encode" do
- expect { @yaml.render("foo") }.to raise_error(Puppet::Error, /zlib library is not installed/)
+ lambda{ @yaml.encode("foo") }.should raise_error
end
it "should refuse to decode" do
- expect { @yaml.intern(String, "foo") }.to raise_error(Puppet::Error, /zlib library is not installed/)
+ lambda{ @yaml.decode("foo") }.should raise_error
end
end
describe "when zlib is not installed" do
it "use_zlib? should return false" do