Updated mcollective.init according to OSCI-658
[packages/precise/mcollective.git] / spec / unit / facts_spec.rb
diff --git a/spec/unit/facts_spec.rb b/spec/unit/facts_spec.rb
new file mode 100755 (executable)
index 0000000..2705242
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/env rspec
+
+require 'spec_helper'
+
+module MCollective
+  describe Facts do
+    before do
+      class Facts::Testfacts<Facts::Base; end
+
+      PluginManager.delete("facts_plugin")
+      PluginManager << {:type => "facts_plugin", :class => "MCollective::Facts::Testfacts"}
+    end
+
+    describe "#has_fact?" do
+      it "should correctly report fact presense" do
+        Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
+
+        Facts.has_fact?("foo", "foo").should == false
+        Facts.has_fact?("foo", "bar").should == true
+      end
+    end
+
+    describe "#get_fact" do
+      it "should return the correct fact" do
+        Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
+
+        Facts.get_fact("foo").should == "bar"
+      end
+    end
+
+    describe "#[]" do
+      it "should return the correct fact" do
+        Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => "bar"})
+
+        Facts["foo"].should == "bar"
+      end
+    end
+  end
+end