summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/reference_serializer_spec.rb
blob: d696dc1931c9100231b7510800bf350df8268ac5 (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
#!/usr/bin/env ruby

require 'spec_helper'
require 'puppet/util/rails/reference_serializer'

class SerializeTester
  include Puppet::Util::ReferenceSerializer
end

describe Puppet::Util::ReferenceSerializer do
  before do
    @tester = SerializeTester.new
  end

  describe "when serializing" do
    it "should yaml-dump resource references" do
      ref = Puppet::Resource.new("file", "/foo")
      @tester.serialize_value(ref).should =~ /^---/
    end

    it "should convert the boolean 'true' into the string 'true'" do
      @tester.serialize_value(true).should == "true"
    end

    it "should convert the boolean 'false' into the string 'false'" do
      @tester.serialize_value(false).should == "false"
    end

    it "should return all other values" do
      @tester.serialize_value("foo").should == "foo"
    end
  end

  describe "when unserializing" do
    it "should yaml-load values that look like yaml" do
      yaml = YAML.dump(%w{a b c})
      @tester.unserialize_value(yaml).should == %w{a b c}
    end

    it "should convert the string 'true' into the boolean 'true'" do
      @tester.unserialize_value("true").should == true
    end

    it "should convert the string 'false' into the boolean 'false'" do
      @tester.unserialize_value("false").should == false
    end

    it "should return all other values" do
      @tester.unserialize_value("foo").should == "foo"
    end
  end
end