Add PluginManager#clear that removes all registered plugins and use
this to clear all plugins from the PluginManager before every test

Signed-off-by: R.I.Pienaar <[email protected]>
---
Local-branch: ticket/master/7176
 lib/mcollective/pluginmanager.rb |    5 +++++
 spec/spec_helper.rb              |    4 ++++
 spec/unit/config_spec.rb         |    4 ----
 spec/unit/facts/base_spec.rb     |    4 ----
 spec/unit/facts_spec.rb          |    5 -----
 spec/unit/security/base_spec.rb  |    4 ----
 spec/unit/security/psk_spec.rb   |    4 ----
 spec/unit/util_spec.rb           |    3 +++
 website/changelog.md             |    1 +
 9 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/lib/mcollective/pluginmanager.rb b/lib/mcollective/pluginmanager.rb
index 0690463..496ecbd 100644
--- a/lib/mcollective/pluginmanager.rb
+++ b/lib/mcollective/pluginmanager.rb
@@ -63,6 +63,11 @@ module MCollective
             @plugins.keys
         end
 
+        # deletes all registered plugins
+        def self.clear
+            @plugins.clear
+        end
+
         # Gets a plugin by type
         def self.[](plugin)
             raise("No plugin #{plugin} defined") unless 
@plugins.include?(plugin)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 752897c..26be863 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -15,4 +15,8 @@ require 'tmpdir'
 
 RSpec.configure do |config|
     config.mock_with :mocha
+
+    config.before :each do
+        MCollective::PluginManager.clear
+    end
 end
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index cbd9b4f..522acfe 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -17,10 +17,6 @@ module MCollective
                 FileUtils.mkdir(@plugindir)
             end
 
-            after do
-                FileUtils.remove_entry @tmpdir
-            end
-
             it "should not fail if the supplied directory is missing" do
                 Config.instance.read_plugin_config_dir("/nonexisting")
                 Config.instance.pluginconf.should == nil
diff --git a/spec/unit/facts/base_spec.rb b/spec/unit/facts/base_spec.rb
index 5270db5..3f9b4cc 100644
--- a/spec/unit/facts/base_spec.rb
+++ b/spec/unit/facts/base_spec.rb
@@ -11,10 +11,6 @@ module MCollective::Facts
             MCollective::PluginManager << {:type => "facts_plugin", :class => 
"MCollective::Facts::Testfacts"}
         end
 
-        after do
-            MCollective::PluginManager.delete("facts_plugin")
-        end
-
         describe "#inherited" do
             it "should add classes to the plugin manager" do
                 MCollective::PluginManager.stubs("<<").with({:type => 
"facts_plugin", :class => "MCollective::Facts::Bar"})
diff --git a/spec/unit/facts_spec.rb b/spec/unit/facts_spec.rb
index 9a53410..ecb208d 100644
--- a/spec/unit/facts_spec.rb
+++ b/spec/unit/facts_spec.rb
@@ -11,11 +11,6 @@ module MCollective
             PluginManager << {:type => "facts_plugin", :class => 
"MCollective::Facts::Testfacts"}
         end
 
-        after do
-            PluginManager.delete("facts_plugin")
-        end
-
-
         describe "#has_fact?" do
             it "should correctly report fact presense" do
                 
Facts::Testfacts.any_instance.stubs("load_facts_from_source").returns({"foo" => 
"bar"})
diff --git a/spec/unit/security/base_spec.rb b/spec/unit/security/base_spec.rb
index 882d152..5304371 100644
--- a/spec/unit/security/base_spec.rb
+++ b/spec/unit/security/base_spec.rb
@@ -23,10 +23,6 @@ module MCollective::Security
             @plugin = Base.new
         end
 
-        after do
-            MCollective::PluginManager.delete("global_stats")
-        end
-
         describe "#validate_filter?" do
             it "should pass on empty filter" do
                 MCollective::Util.stubs("empty_filter?").returns(true)
diff --git a/spec/unit/security/psk_spec.rb b/spec/unit/security/psk_spec.rb
index aed713a..66a9497 100644
--- a/spec/unit/security/psk_spec.rb
+++ b/spec/unit/security/psk_spec.rb
@@ -25,10 +25,6 @@ module MCollective::Security
             @plugin = Psk.new
         end
 
-        after do
-            MCollective::PluginManager.delete("global_stats")
-        end
-
         describe "#decodemsg" do
             it "should correctly decode a message" do
                 @plugin.stubs("validrequest?").returns(true).once
diff --git a/spec/unit/util_spec.rb b/spec/unit/util_spec.rb
index 5e9dfab..a9cfbfd 100644
--- a/spec/unit/util_spec.rb
+++ b/spec/unit/util_spec.rb
@@ -6,6 +6,9 @@ module MCollective
     describe Util do
         before do
             class MCollective::Connector::Stomp<MCollective::Connector::Base; 
end
+
+            PluginManager.clear
+            PluginManager << {:type => "connector_plugin", :class => 
MCollective::Connector::Stomp.new}
         end
 
         describe "#shellescape" do
diff --git a/website/changelog.md b/website/changelog.md
index 17d85d2..365cde7 100644
--- a/website/changelog.md
+++ b/website/changelog.md
@@ -11,6 +11,7 @@ title: Changelog
 
 |Date|Description|Ticket|
 |----|-----------|------|
+|2011/04/20|Add a clear method to the PluginManager that deletes all plugins, 
improve test isolation|7176|
 |2011/04/19|Abstract the creation of request and reply hashes to simplify 
connector plugin development|5701|
 |2011/04/15|Improve the shellsafe validator and add a Util method to do shell 
escaping|7066|
 |2011/04/14|Update Rakefile to have a mail_patches task|6874|
-- 
1.7.1

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to