summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Algorta <diego@oboxodo.com>2009-08-13 14:49:12 -0300
committerPaul Nasrat <pnasrat@googlemail.com>2009-08-14 07:52:26 +0100
commit0e0483ae3f00d408766a850823e3120caedfb9fc (patch)
treeb2203d5393a13c0c505b78772fb465aba360af2d
parentfe41fb80dda8c96814b7a57875331b731dd04395 (diff)
downloadfacter-0e0483ae3f00d408766a850823e3120caedfb9fc.tar.gz
facter-0e0483ae3f00d408766a850823e3120caedfb9fc.tar.xz
facter-0e0483ae3f00d408766a850823e3120caedfb9fc.zip
Fix bug where you'd get an 'undefined method' error if trying to access a fact's value when collection has not being yet initialized.
-rw-r--r--lib/facter.rb2
-rwxr-xr-xspec/unit/facter.rb16
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/facter.rb b/lib/facter.rb
index d75f275..6e05495 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -120,7 +120,7 @@ module Facter
name = name.to_s.sub(/\?$/,'')
end
- if fact = @collection.fact(name)
+ if fact = collection.fact(name)
if question
value = fact.value.downcase
args.each do |arg|
diff --git a/spec/unit/facter.rb b/spec/unit/facter.rb
index bdef726..f248aa7 100755
--- a/spec/unit/facter.rb
+++ b/spec/unit/facter.rb
@@ -82,6 +82,22 @@ describe Facter do
end
end
+ describe "when asked for a fact as an undefined Facter class method" do
+ describe "and the collection is already initialized" do
+ it "should return the fact's value" do
+ Facter.collection
+ Facter.ipaddress.should == Facter['ipaddress'].value
+ end
+ end
+
+ describe "and the collection has been just reset" do
+ it "should return the fact's value" do
+ Facter.reset
+ Facter.ipaddress.should == Facter['ipaddress'].value
+ end
+ end
+ end
+
describe "when passed code as a block" do
it "should execute the provided block" do
Facter.add("block_testing") { setcode { "foo" } }