summaryrefslogtreecommitdiffstats
path: root/spec/unit/util/ldap/generator_spec.rb
blob: a6c69de83b141f00581be44ee758626579b523ac (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
#!/usr/bin/env ruby
#
#  Created by Luke Kanies on 2008-3-28.
#  Copyright (c) 2008. All rights reserved.

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

require 'puppet/util/ldap/generator'

describe Puppet::Util::Ldap::Generator do
    before do
        @generator = Puppet::Util::Ldap::Generator.new(:uno)
    end

    it "should require a parameter name at initialization" do
        lambda { Puppet::Util::Ldap::Generator.new }.should raise_error
    end

    it "should always return its name as a string" do
        g = Puppet::Util::Ldap::Generator.new(:myname)
        g.name.should == "myname"
    end

    it "should provide a method for declaring the source parameter" do
        @generator.from(:dos)
    end

    it "should always return a set source as a string" do
        @generator.from(:dos)
        @generator.source.should == "dos"
    end

    it "should return the source as nil if there is no source" do
        @generator.source.should be_nil
    end

    it "should return itself when declaring the source" do
        @generator.from(:dos).should equal(@generator)
    end

    it "should run the provided block when asked to generate the value" do
        @generator.with { "yayness" }
        @generator.generate().should == "yayness"
    end

    it "should pass in any provided value to the block" do
        @generator.with { |value| value.upcase }
        @generator.generate("myval").should == "MYVAL"
    end

    it "should return itself when declaring the code used for generating" do
        @generator.with { |value| value.upcase }.should equal(@generator)
    end
end