3
require File.dirname(__FILE__) + '/../../spec_helper'
5
require 'puppet/node/environment'
7
describe Puppet::Node::Environment do
8
it "should provide a list of valid environments" do
9
Puppet::Node::Environment.valid.should be_instance_of(Array)
12
it "should determine its list of valid environments from splitting the :environments setting on commas" do
13
Puppet.settings.stubs(:value).with(:environments).returns("one,two")
14
Puppet::Node::Environment.valid.collect { |e| e.to_s }.sort.should == %w{one two}.sort
17
it "should not use an environment when determining the list of valid environments" do
18
Puppet.settings.expects(:value).with(:environments).returns("one,two")
19
Puppet::Node::Environment.valid
22
it "should provide a means of identifying invalid environments" do
23
Puppet.settings.expects(:value).with(:environments).returns("one,two")
24
Puppet::Node::Environment.valid?(:three).should be_false
27
it "should provide a means of identifying valid environments" do
28
Puppet.settings.expects(:value).with(:environments).returns("one,two")
29
Puppet::Node::Environment.valid?(:one).should be_true
32
it "should be used to determine when an environment setting is valid" do
33
Puppet.settings.expects(:value).with(:environments).returns("one,two")
34
proc { Puppet.settings[:environment] = :three }.should raise_error(ArgumentError)
37
it "should use the default environment if no name is provided while initializing an environment" do
38
Puppet.settings.expects(:value).with(:environments).returns("one,two")
39
Puppet.settings.expects(:value).with(:environment).returns("one")
40
Puppet::Node::Environment.new().name.should == :one
43
it "should treat environment instances as singletons" do
44
Puppet.settings.stubs(:value).with(:environments).returns("one")
45
Puppet::Node::Environment.new("one").should equal(Puppet::Node::Environment.new("one"))
48
it "should treat an environment specified as names or strings as equivalent" do
49
Puppet.settings.stubs(:value).with(:environments).returns("one")
50
Puppet::Node::Environment.new(:one).should equal(Puppet::Node::Environment.new("one"))
53
it "should fail if an invalid environment instance is asked for" do
54
Puppet.settings.stubs(:value).with(:environments).returns("one,two")
55
proc { Puppet::Node::Environment.new("three") }.should raise_error(ArgumentError)
58
it "should consider environments that are empty strings invalid" do
59
Puppet::Node::Environment.valid?("").should be_false
62
it "should fail if a no-longer-valid environment instance is asked for" do
63
Puppet.settings.expects(:value).with(:environments).returns("one")
64
Puppet::Node::Environment.new("one")
65
Puppet.settings.expects(:value).with(:environments).returns("two")
66
proc { Puppet::Node::Environment.new("one") }.should raise_error(ArgumentError)
70
describe Puppet::Node::Environment, " when modeling a specific environment" do
72
Puppet.settings.expects(:value).with(:environments).returns("testing")
75
it "should have a method for returning the environment name" do
76
Puppet::Node::Environment.new("testing").name.should == :testing
79
it "should provide an array-like accessor method for returning any environment-specific setting" do
80
env = Puppet::Node::Environment.new("testing")
81
env.should respond_to(:[])
84
it "should ask the Puppet settings instance for the setting qualified with the environment name" do
85
Puppet.settings.expects(:value).with("myvar", :testing).returns("myval")
86
env = Puppet::Node::Environment.new("testing")
87
env["myvar"].should == "myval"