pairing with luke, nagios_command provider skeleton
[vinpup.git] / spec / unit / node / environment.rb
blob8433a98774c6801d5a7a3da2addbc593834f0928
1 #!/usr/bin/env ruby
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)
10     end
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
15     end
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
20     end
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
25     end
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
30     end
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)
35     end
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
41     end
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"))
46     end
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"))
51     end
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)
56     end
58     it "should consider environments that are empty strings invalid" do
59         Puppet::Node::Environment.valid?("").should be_false
60     end
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)
67     end
68 end
70 describe Puppet::Node::Environment, " when modeling a specific environment" do
71     before do
72         Puppet.settings.expects(:value).with(:environments).returns("testing")
73     end
75     it "should have a method for returning the environment name" do
76         Puppet::Node::Environment.new("testing").name.should == :testing
77     end
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(:[])
82     end
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"
88     end
89 end