summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/formats.rb
blob: a7d74e95c1cc586d3825e517ecb98ab4ee61e835 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env ruby

require File.dirname(__FILE__) + '/../../spec_helper'

require 'puppet/network/formats'

describe "Puppet Network Format" do
    it "should include a yaml format" do
        Puppet::Network::FormatHandler.format(:yaml).should_not be_nil
    end

    describe "yaml" do
        before do
            @yaml = Puppet::Network::FormatHandler.format(:yaml)
        end

        it "should have its mime type set to text/yaml" do
            @yaml.mime.should == "text/yaml"
        end

        it "should be supported on Strings" do
            @yaml.should be_supported(String)
        end

        it "should render by calling 'to_yaml' on the instance" do
            instance = mock 'instance'
            instance.expects(:to_yaml).returns "foo"
            @yaml.render(instance).should == "foo"
        end

        it "should render multiple instances by calling 'to_yaml' on the array" do
            instances = [mock('instance')]
            instances.expects(:to_yaml).returns "foo"
            @yaml.render_multiple(instances).should == "foo"
        end

        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 intern multiples by calling 'YAML.load'" do
            text = "foo"
            YAML.expects(:load).with("foo").returns "bar"
            @yaml.intern_multiple(String, text).should == "bar"
        end
    end

    it "should include a marshal format" do
        Puppet::Network::FormatHandler.format(:marshal).should_not be_nil
    end

    describe "marshal" do
        before do
            @marshal = Puppet::Network::FormatHandler.format(:marshal)
        end

        it "should have its mime type set to text/marshal" do
            Puppet::Network::FormatHandler.format(:marshal).mime.should == "text/marshal"
        end

        it "should be supported on Strings" do
            @marshal.should be_supported(String)
        end

        it "should render by calling 'Marshal.dump' on the instance" do
            instance = mock 'instance'
            Marshal.expects(:dump).with(instance).returns "foo"
            @marshal.render(instance).should == "foo"
        end

        it "should render multiple instances by calling 'to_marshal' on the array" do
            instances = [mock('instance')]

            Marshal.expects(:dump).with(instances).returns "foo"
            @marshal.render_multiple(instances).should == "foo"
        end

        it "should intern by calling 'Marshal.load'" do
            text = "foo"
            Marshal.expects(:load).with("foo").returns "bar"
            @marshal.intern(String, text).should == "bar"
        end

        it "should intern multiples by calling 'Marshal.load'" do
            text = "foo"
            Marshal.expects(:load).with("foo").returns "bar"
            @marshal.intern_multiple(String, text).should == "bar"
        end
    end
end