diff options
author | Luke Kanies <luke@madstop.com> | 2008-05-15 14:30:29 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-05-15 14:30:29 -0500 |
commit | 1ba2bed578debd251d2b9514039082eaa3f136df (patch) | |
tree | 907098a846dd7215d59ccfec2d470318bb619fa8 /spec | |
parent | be0a8031fbf8e4a2d608ab600c37c1b01dec16a1 (diff) | |
download | facter-1ba2bed578debd251d2b9514039082eaa3f136df.tar.gz facter-1ba2bed578debd251d2b9514039082eaa3f136df.tar.xz facter-1ba2bed578debd251d2b9514039082eaa3f136df.zip |
Moving all of the support classes to util/.
This makes it easier for our loader to distinguish between
code that Facter uses and new facts.
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/facter.rb | 9 | ||||
-rwxr-xr-x | spec/unit/util/collection.rb (renamed from spec/unit/collection.rb) | 38 | ||||
-rwxr-xr-x | spec/unit/util/confine.rb (renamed from spec/unit/confine.rb) | 22 | ||||
-rwxr-xr-x | spec/unit/util/fact.rb (renamed from spec/unit/fact.rb) | 42 | ||||
-rwxr-xr-x | spec/unit/util/loader.rb (renamed from spec/unit/loader.rb) | 18 | ||||
-rwxr-xr-x | spec/unit/util/resolution.rb (renamed from spec/unit/resolution.rb) | 50 |
6 files changed, 92 insertions, 87 deletions
diff --git a/spec/integration/facter.rb b/spec/integration/facter.rb index b503c9d..e1f2025 100755 --- a/spec/integration/facter.rb +++ b/spec/integration/facter.rb @@ -8,10 +8,15 @@ describe Facter do Facter.loadfacts end + after do + Facter.reset + end + it "should create a new collection if one does not exist" do Facter.reset - Facter::Collection.expects(:new).returns "coll" - Facter.collection.should == "coll" + coll = mock('coll') + Facter::Util::Collection.stubs(:new).returns coll + Facter.collection.should equal(coll) Facter.reset end diff --git a/spec/unit/collection.rb b/spec/unit/util/collection.rb index d69888e..e88de06 100755 --- a/spec/unit/collection.rb +++ b/spec/unit/util/collection.rb @@ -1,22 +1,22 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../spec_helper' -require 'facter/collection' +require 'facter/util/collection' -describe Facter::Collection do +describe Facter::Util::Collection do it "should have a method for adding facts" do - Facter::Collection.new.should respond_to(:add) + Facter::Util::Collection.new.should respond_to(:add) end describe "when adding facts" do before do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new end it "should create a new fact if no fact with the same name already exists" do fact = mock 'fact' - Facter::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact + Facter::Util::Fact.expects(:new).with { |name, *args| name == :myname }.returns fact @coll.add(:myname) end @@ -24,7 +24,7 @@ describe Facter::Collection do describe "and a block is provided" do it "should use the block to add a resolution to the fact" do fact = mock 'fact' - Facter::Fact.expects(:new).returns fact + Facter::Util::Fact.expects(:new).returns fact fact.expects(:add) @@ -34,12 +34,12 @@ describe Facter::Collection do end it "should have a method for retrieving facts by name" do - Facter::Collection.new.should respond_to(:fact) + Facter::Util::Collection.new.should respond_to(:fact) end describe "when retrieving facts" do before do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @fact = @coll.add("YayNess") end @@ -58,12 +58,12 @@ describe Facter::Collection do end it "should have a method for returning a fact's value" do - Facter::Collection.new.should respond_to(:value) + Facter::Util::Collection.new.should respond_to(:value) end describe "when returning a fact's value" do before do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @fact = @coll.add("YayNess") @fact.stubs(:value).returns "result" @@ -85,13 +85,13 @@ describe Facter::Collection do end it "should return the fact's value when the array index method is used" do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @coll.expects(:value).with("myfact").returns "foo" @coll["myfact"].should == "foo" end it "should have a method for flushing all facts" do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @fact = @coll.add("YayNess") @fact.expects(:flush) @@ -100,7 +100,7 @@ describe Facter::Collection do end it "should have a method that returns all fact names" do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @coll.add(:one) @coll.add(:two) @@ -108,12 +108,12 @@ describe Facter::Collection do end it "should have a method for returning a hash of fact values" do - Facter::Collection.new.should respond_to(:to_hash) + Facter::Util::Collection.new.should respond_to(:to_hash) end describe "when returning a hash of values" do before do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @fact = @coll.add(:one) @fact.stubs(:value).returns "me" end @@ -130,16 +130,16 @@ describe Facter::Collection do end it "should have a method for iterating over all facts" do - Facter::Collection.new.should respond_to(:each) + Facter::Util::Collection.new.should respond_to(:each) end it "should include Enumerable" do - Facter::Collection.ancestors.should be_include(Enumerable) + Facter::Util::Collection.ancestors.should be_include(Enumerable) end describe "when iterating over facts" do before do - @coll = Facter::Collection.new + @coll = Facter::Util::Collection.new @one = @coll.add(:one) @two = @coll.add(:two) end diff --git a/spec/unit/confine.rb b/spec/unit/util/confine.rb index ae122ea..5c1ce3b 100755 --- a/spec/unit/confine.rb +++ b/spec/unit/util/confine.rb @@ -1,41 +1,41 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../spec_helper' -require 'facter/confine' +require 'facter/util/confine' -describe Facter::Confine do +describe Facter::Util::Confine do it "should require a fact name" do - Facter::Confine.new("yay", true).fact.should == "yay" + Facter::Util::Confine.new("yay", true).fact.should == "yay" end it "should accept a value specified individually" do - Facter::Confine.new("yay", "test").values.should == ["test"] + Facter::Util::Confine.new("yay", "test").values.should == ["test"] end it "should accept multiple values specified at once" do - Facter::Confine.new("yay", "test", "other").values.should == ["test", "other"] + Facter::Util::Confine.new("yay", "test", "other").values.should == ["test", "other"] end it "should convert all values to strings" do - Facter::Confine.new("yay", :test).values.should == %w{test} + Facter::Util::Confine.new("yay", :test).values.should == %w{test} end it "should fail if no fact name is provided" do - lambda { Facter::Confine.new(nil, :test) }.should raise_error(ArgumentError) + lambda { Facter::Util::Confine.new(nil, :test) }.should raise_error(ArgumentError) end it "should fail if no values were provided" do - lambda { Facter::Confine.new("yay") }.should raise_error(ArgumentError) + lambda { Facter::Util::Confine.new("yay") }.should raise_error(ArgumentError) end it "should have a method for testing whether it matches" do - Facter::Confine.new("yay", :test).should respond_to(:true?) + Facter::Util::Confine.new("yay", :test).should respond_to(:true?) end describe "when evaluating" do before do - @confine = Facter::Confine.new("yay", "one", "two") + @confine = Facter::Util::Confine.new("yay", "one", "two") @fact = mock 'fact' Facter.stubs(:[]).returns @fact end diff --git a/spec/unit/fact.rb b/spec/unit/util/fact.rb index 3772d0f..1652032 100755 --- a/spec/unit/fact.rb +++ b/spec/unit/util/fact.rb @@ -1,37 +1,37 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../spec_helper' -require 'facter/fact' +require 'facter/util/fact' -describe Facter::Fact do +describe Facter::Util::Fact do it "should require a name" do - lambda { Facter::Fact.new }.should raise_error(ArgumentError) + lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError) end it "should always downcase the name and convert it to a symbol" do - Facter::Fact.new("YayNess").name.should == :yayness + Facter::Util::Fact.new("YayNess").name.should == :yayness end it "should default to its name converted to a string as its ldapname" do - Facter::Fact.new("YayNess").ldapname.should == "yayness" + Facter::Util::Fact.new("YayNess").ldapname.should == "yayness" end it "should allow specifying the ldap name at initialization" do - Facter::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness" + Facter::Util::Fact.new("YayNess", :ldapname => "fooness").ldapname.should == "fooness" end it "should fail if an unknown option is provided" do - lambda { Facter::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError) + lambda { Facter::Util::Fact.new('yay', :foo => :bar) }.should raise_error(ArgumentError) end it "should have a method for adding resolution mechanisms" do - Facter::Fact.new("yay").should respond_to(:add) + Facter::Util::Fact.new("yay").should respond_to(:add) end describe "when adding resolution mechanisms" do before do - @fact = Facter::Fact.new("yay") + @fact = Facter::Util::Fact.new("yay") @resolution = mock 'resolution' @resolution.stub_everything @@ -43,7 +43,7 @@ describe Facter::Fact do end it "should create a new resolution instance" do - Facter::Resolution.expects(:new).returns @resolution + Facter::Util::Resolution.expects(:new).returns @resolution @fact.add { } end @@ -51,7 +51,7 @@ describe Facter::Fact do it "should instance_eval the passed block on the new resolution" do @resolution.expects(:instance_eval) - Facter::Resolution.stubs(:new).returns @resolution + Facter::Util::Resolution.stubs(:new).returns @resolution @fact.add { } end @@ -60,7 +60,7 @@ describe Facter::Fact do r1 = stub 'r1', :length => 1 r2 = stub 'r2', :length => 2 r3 = stub 'r3', :length => 0 - Facter::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @fact.add { } @@ -70,23 +70,23 @@ describe Facter::Fact do end it "should be able to return a value" do - Facter::Fact.new("yay").should respond_to(:value) + Facter::Util::Fact.new("yay").should respond_to(:value) end describe "when returning a value" do before do - @fact = Facter::Fact.new("yay") + @fact = Facter::Util::Fact.new("yay") end it "should return nil if there are no resolutions" do - Facter::Fact.new("yay").value.should be_nil + Facter::Util::Fact.new("yay").value.should be_nil end it "should return the first value returned by a resolution" do r1 = stub 'r1', :length => 2, :value => nil, :suitable? => true r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true r3 = stub 'r3', :length => 0, :value => "foo", :suitable? => true - Facter::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) + Facter::Util::Resolution.expects(:new).times(3).returns(r1).returns(r2).returns(r3) @fact.add { } @fact.add { } @fact.add { } @@ -97,7 +97,7 @@ describe Facter::Fact do it "should short-cut returning the value once one is found" do r1 = stub 'r1', :length => 2, :value => "foo", :suitable? => true r2 = stub 'r2', :length => 1, :suitable? => true # would fail if 'value' were asked for - Facter::Resolution.expects(:new).times(2).returns(r1).returns(r2) + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } @@ -107,7 +107,7 @@ describe Facter::Fact do it "should skip unsuitable resolutions" do r1 = stub 'r1', :length => 2, :suitable? => false # would fail if 'value' were asked for' r2 = stub 'r2', :length => 1, :value => "yay", :suitable? => true - Facter::Resolution.expects(:new).times(2).returns(r1).returns(r2) + Facter::Util::Resolution.expects(:new).times(2).returns(r1).returns(r2) @fact.add { } @fact.add { } @@ -116,7 +116,7 @@ describe Facter::Fact do it "should return nil if the value is the empty string" do r1 = stub 'r1', :suitable? => true, :value => "" - Facter::Resolution.expects(:new).returns r1 + Facter::Util::Resolution.expects(:new).returns r1 @fact.add { } @fact.value.should be_nil @@ -124,6 +124,6 @@ describe Facter::Fact do end it "should have a method for flushing the cached fact" do - Facter::Fact.new(:foo).should respond_to(:flush) + Facter::Util::Fact.new(:foo).should respond_to(:flush) end end diff --git a/spec/unit/loader.rb b/spec/unit/util/loader.rb index 75146e1..4c0d777 100755 --- a/spec/unit/loader.rb +++ b/spec/unit/util/loader.rb @@ -1,8 +1,8 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../spec_helper' -require 'facter/loader' +require 'facter/util/loader' # Make sure we have a Puppet constant, so we can test # loading Puppet facts. @@ -10,7 +10,7 @@ unless defined?(Puppet) class Puppet; end end -describe Facter::Loader do +describe Facter::Util::Loader do def with_env(values) old = {} values.each do |var, value| @@ -30,20 +30,20 @@ describe Facter::Loader do end it "should have a method for loading individual facts by name" do - Facter::Loader.new.should respond_to(:load) + Facter::Util::Loader.new.should respond_to(:load) end it "should have a method for loading all facts" do - Facter::Loader.new.should respond_to(:load_all) + Facter::Util::Loader.new.should respond_to(:load_all) end it "should have a method for returning directories containing facts" do - Facter::Loader.new.should respond_to(:search_path) + Facter::Util::Loader.new.should respond_to(:search_path) end describe "when determining the search path" do before do - @loader = Facter::Loader.new + @loader = Facter::Util::Loader.new @settings = mock 'settings' @settings.stubs(:value).returns "/eh" Puppet.stubs(:settings).returns @settings @@ -84,7 +84,7 @@ describe Facter::Loader do describe "when loading facts" do before do - @loader = Facter::Loader.new + @loader = Facter::Util::Loader.new @loader.stubs(:search_path).returns [] end @@ -135,7 +135,7 @@ describe Facter::Loader do describe "when loading all facts" do before do - @loader = Facter::Loader.new + @loader = Facter::Util::Loader.new @loader.stubs(:search_path).returns [] end diff --git a/spec/unit/resolution.rb b/spec/unit/util/resolution.rb index a54b872..493ee3a 100755 --- a/spec/unit/resolution.rb +++ b/spec/unit/util/resolution.rb @@ -1,25 +1,25 @@ #!/usr/bin/env ruby -require File.dirname(__FILE__) + '/../spec_helper' +require File.dirname(__FILE__) + '/../../spec_helper' -require 'facter/resolution' +require 'facter/util/resolution' -describe Facter::Resolution do +describe Facter::Util::Resolution do it "should require a name" do - lambda { Facter::Resolution.new }.should raise_error(ArgumentError) + lambda { Facter::Util::Resolution.new }.should raise_error(ArgumentError) end it "should have a name" do - Facter::Resolution.new("yay").name.should == "yay" + Facter::Util::Resolution.new("yay").name.should == "yay" end it "should have a method for setting the code" do - Facter::Resolution.new("yay").should respond_to(:setcode) + Facter::Util::Resolution.new("yay").should respond_to(:setcode) end describe "when setting the code" do before do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") end it "should default to /bin/sh as the interpreter if a string is provided" do @@ -49,25 +49,25 @@ describe Facter::Resolution do end it "should be able to return a value" do - Facter::Resolution.new("yay").should respond_to(:value) + Facter::Util::Resolution.new("yay").should respond_to(:value) end describe "when returning the value" do before do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") end describe "and the code is a string" do it "should return the result of executing the code with the interpreter" do @resolve.setcode "/bin/foo" - Facter::Resolution.expects(:exec).with("/bin/foo", "/bin/sh").returns "yup" + Facter::Util::Resolution.expects(:exec).with("/bin/foo", "/bin/sh").returns "yup" @resolve.value.should == "yup" end it "should return nil if the value is an empty string" do @resolve.setcode "/bin/foo" - Facter::Resolution.stubs(:exec).returns "" + Facter::Util::Resolution.stubs(:exec).returns "" @resolve.value.should be_nil end end @@ -86,41 +86,41 @@ describe Facter::Resolution do end it "should return its value when converted to a string" do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") @resolve.expects(:value).returns "myval" @resolve.to_s.should == "myval" end it "should allow the adding of confines" do - Facter::Resolution.new("yay").should respond_to(:confine) + Facter::Util::Resolution.new("yay").should respond_to(:confine) end it "should provide a method for returning the number of confines" do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") @resolve.confine "one" => "foo", "two" => "fee" @resolve.length.should == 2 end it "should return 0 confines when no confines have been added" do - Facter::Resolution.new("yay").length.should == 0 + Facter::Util::Resolution.new("yay").length.should == 0 end it "should have a method for determining if it is suitable" do - Facter::Resolution.new("yay").should respond_to(:suitable?) + Facter::Util::Resolution.new("yay").should respond_to(:suitable?) end describe "when adding confines" do before do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") end it "should accept a hash of fact names and values" do lambda { @resolve.confine :one => "two" }.should_not raise_error end - it "should create a Confine instance for every argument in the provided hash" do - Facter::Confine.expects(:new).with("one", "foo") - Facter::Confine.expects(:new).with("two", "fee") + it "should create a Util::Confine instance for every argument in the provided hash" do + Facter::Util::Confine.expects(:new).with("one", "foo") + Facter::Util::Confine.expects(:new).with("two", "fee") @resolve.confine "one" => "foo", "two" => "fee" end @@ -129,7 +129,7 @@ describe Facter::Resolution do describe "when determining suitability" do before do - @resolve = Facter::Resolution.new("yay") + @resolve = Facter::Util::Resolution.new("yay") end it "should always be suitable if no confines have been added" do @@ -139,7 +139,7 @@ describe Facter::Resolution do it "should be unsuitable if any provided confines return false" do confine1 = mock 'confine1', :true? => true confine2 = mock 'confine2', :true? => false - Facter::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) @resolve.confine :one => :two, :three => :four @resolve.should_not be_suitable @@ -148,7 +148,7 @@ describe Facter::Resolution do it "should be suitable if all provided confines return true" do confine1 = mock 'confine1', :true? => true confine2 = mock 'confine2', :true? => true - Facter::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) + Facter::Util::Confine.expects(:new).times(2).returns(confine1).then.returns(confine2) @resolve.confine :one => :two, :three => :four @resolve.should be_suitable @@ -156,13 +156,13 @@ describe Facter::Resolution do end it "should have a class method for executing code" do - Facter::Resolution.should respond_to(:exec) + Facter::Util::Resolution.should respond_to(:exec) end # It's not possible, AFAICT, to mock %x{}, so I can't really test this bit. describe "when executing code" do it "should fail if any interpreter other than /bin/sh is requested" do - lambda { Facter::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError) + lambda { Facter::Util::Resolution.exec("/something", "/bin/perl") }.should raise_error(ArgumentError) end end end |