File: scope_spec.rb

package info (click to toggle)
puppet 3.7.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 18,896 kB
  • sloc: ruby: 210,387; sh: 2,050; xml: 1,554; lisp: 300; makefile: 142; python: 108; sql: 103; yacc: 72
file content (89 lines) | stat: -rw-r--r-- 2,660 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'
require 'hiera/scope'

require 'puppet_spec/scope'

describe Hiera::Scope do
  include PuppetSpec::Scope

  let(:real) { create_test_scope_for_node("test_node") }
  let(:scope) { Hiera::Scope.new(real) }

  describe "#initialize" do
    it "should store the supplied puppet scope" do
      scope.real.should == real
    end
  end

  describe "#[]" do
    it "should return nil when no value is found" do
      scope["foo"].should == nil
    end

    it "should treat '' as nil" do
      real["foo"] = ""

      scope["foo"].should == nil
    end

    it "should return found data" do
      real["foo"] = "bar"

      scope["foo"].should == "bar"
    end

    it "preserves the case of a string that is found" do
      real["foo"] = "CAPITAL!"

      scope["foo"].should == "CAPITAL!"
    end

    it "aliases $module_name as calling_module" do
      real["module_name"] = "the_module"

      scope["calling_module"].should == "the_module"
    end

    it "uses the name of the of the scope's class as the calling_class" do
      real.source = Puppet::Resource::Type.new(:hostclass,
                                               "testing",
                                               :module_name => "the_module")

      scope["calling_class"].should == "testing"
    end

    it "downcases the calling_class" do
      real.source = Puppet::Resource::Type.new(:hostclass,
                                               "UPPER CASE",
                                               :module_name => "the_module")

      scope["calling_class"].should == "upper case"
    end

    it "looks for the class which includes the defined type as the calling_class" do
      parent = create_test_scope_for_node("parent")
      real.parent = parent
      parent.source = Puppet::Resource::Type.new(:hostclass,
                                                 "name_of_the_class_including_the_definition",
                                                 :module_name => "class_module")
      real.source = Puppet::Resource::Type.new(:definition,
                                               "definition_name",
                                               :module_name => "definition_module")

      scope["calling_class"].should == "name_of_the_class_including_the_definition"
    end
  end

  describe "#include?" do
    it "should correctly report missing data" do
      real["foo"] = ""

      scope.include?("foo").should == false
    end

    it "should always return true for calling_class and calling_module" do
      scope.include?("calling_class").should == true
      scope.include?("calling_module").should == true
    end
  end
end