diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:12:17 -0700 |
commit | 3180b9d9b2c844dade1d361326600f7001ec66dd (patch) | |
tree | 98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/configurer | |
parent | 543225970225de5697734bfaf0a6eee996802c04 (diff) | |
download | puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip |
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with
The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people
who learned ruby in the 1900s) uses two-space indentation.
3 Examples:
The code:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
becomes:
end
# Tell getopt which arguments are valid
def test_get_getopt_args
element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new
assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args")
The code:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
becomes:
assert_equal(str, val)
assert_instance_of(Float, result)
end
# Now test it with a passed object
The code:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
becomes:
end
assert_nothing_raised do
klass[:Yay] = "boo"
klass["Cool"] = :yayness
end
Diffstat (limited to 'spec/unit/configurer')
-rwxr-xr-x | spec/unit/configurer/downloader_spec.rb | 266 | ||||
-rwxr-xr-x | spec/unit/configurer/fact_handler_spec.rb | 234 | ||||
-rwxr-xr-x | spec/unit/configurer/plugin_handler_spec.rb | 148 |
3 files changed, 324 insertions, 324 deletions
diff --git a/spec/unit/configurer/downloader_spec.rb b/spec/unit/configurer/downloader_spec.rb index 80de8db48..c57f39fb5 100755 --- a/spec/unit/configurer/downloader_spec.rb +++ b/spec/unit/configurer/downloader_spec.rb @@ -5,184 +5,184 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/configurer/downloader' describe Puppet::Configurer::Downloader do - it "should require a name" do - lambda { Puppet::Configurer::Downloader.new }.should raise_error(ArgumentError) + it "should require a name" do + lambda { Puppet::Configurer::Downloader.new }.should raise_error(ArgumentError) + end + + it "should require a path and a source at initialization" do + lambda { Puppet::Configurer::Downloader.new("name") }.should raise_error(ArgumentError) + end + + it "should set the name, path and source appropriately" do + dler = Puppet::Configurer::Downloader.new("facts", "path", "source") + dler.name.should == "facts" + dler.path.should == "path" + dler.source.should == "source" + end + + it "should be able to provide a timeout value" do + Puppet::Configurer::Downloader.should respond_to(:timeout) + end + + it "should use the configtimeout, converted to an integer, as its timeout" do + Puppet.settings.expects(:value).with(:configtimeout).returns "50" + Puppet::Configurer::Downloader.timeout.should == 50 + end + + describe "when creating the file that does the downloading" do + before do + @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") end - it "should require a path and a source at initialization" do - lambda { Puppet::Configurer::Downloader.new("name") }.should raise_error(ArgumentError) + it "should create a file instance with the right path and source" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:path] == "path" and opts[:source] == "source" } + @dler.file end - it "should set the name, path and source appropriately" do - dler = Puppet::Configurer::Downloader.new("facts", "path", "source") - dler.name.should == "facts" - dler.path.should == "path" - dler.source.should == "source" + it "should tag the file with the downloader name" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:tag] == "foo" } + @dler.file end - it "should be able to provide a timeout value" do - Puppet::Configurer::Downloader.should respond_to(:timeout) + it "should always recurse" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:recurse] == true } + @dler.file end - it "should use the configtimeout, converted to an integer, as its timeout" do - Puppet.settings.expects(:value).with(:configtimeout).returns "50" - Puppet::Configurer::Downloader.timeout.should == 50 + it "should always purge" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:purge] == true } + @dler.file end - describe "when creating the file that does the downloading" do - before do - @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") - end - - it "should create a file instance with the right path and source" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:path] == "path" and opts[:source] == "source" } - @dler.file - end - - it "should tag the file with the downloader name" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:tag] == "foo" } - @dler.file - end - - it "should always recurse" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:recurse] == true } - @dler.file - end - - it "should always purge" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:purge] == true } - @dler.file - end - - it "should never be in noop" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:noop] == false } - @dler.file - end + it "should never be in noop" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:noop] == false } + @dler.file + end - it "should always set the owner to the current UID" do - Process.expects(:uid).returns 51 - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:owner] == 51 } - @dler.file - end + it "should always set the owner to the current UID" do + Process.expects(:uid).returns 51 + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:owner] == 51 } + @dler.file + end - it "should always set the group to the current GID" do - Process.expects(:gid).returns 61 - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:group] == 61 } - @dler.file - end + it "should always set the group to the current GID" do + Process.expects(:gid).returns 61 + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:group] == 61 } + @dler.file + end - it "should always force the download" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:force] == true } - @dler.file - end + it "should always force the download" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:force] == true } + @dler.file + end - it "should never back up when downloading" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:backup] == false } - @dler.file - end + it "should never back up when downloading" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:backup] == false } + @dler.file + end - it "should support providing an 'ignore' parameter" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == [".svn"] } - @dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn") - @dler.file - end + it "should support providing an 'ignore' parameter" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == [".svn"] } + @dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn") + @dler.file + end - it "should split the 'ignore' parameter on whitespace" do - Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == %w{.svn CVS} } - @dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn CVS") - @dler.file - end + it "should split the 'ignore' parameter on whitespace" do + Puppet::Type.type(:file).expects(:new).with { |opts| opts[:ignore] == %w{.svn CVS} } + @dler = Puppet::Configurer::Downloader.new("foo", "path", "source", ".svn CVS") + @dler.file end + end - describe "when creating the catalog to do the downloading" do - before do - @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") - end + describe "when creating the catalog to do the downloading" do + before do + @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") + end - it "should create a catalog and add the file to it" do - file = mock 'file' - catalog = mock 'catalog' + it "should create a catalog and add the file to it" do + file = mock 'file' + catalog = mock 'catalog' - @dler.expects(:file).returns file + @dler.expects(:file).returns file - Puppet::Resource::Catalog.expects(:new).returns catalog - catalog.expects(:add_resource).with(file) + Puppet::Resource::Catalog.expects(:new).returns catalog + catalog.expects(:add_resource).with(file) - @dler.catalog.should equal(catalog) - end + @dler.catalog.should equal(catalog) end + end - describe "when downloading" do - before do - @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") - end + describe "when downloading" do + before do + @dler = Puppet::Configurer::Downloader.new("foo", "path", "source") + end - it "should log that it is downloading" do - Puppet.expects(:info) - Timeout.stubs(:timeout) + it "should log that it is downloading" do + Puppet.expects(:info) + Timeout.stubs(:timeout) - @dler.evaluate - end + @dler.evaluate + end - it "should set a timeout for the download" do - Puppet::Configurer::Downloader.expects(:timeout).returns 50 - Timeout.expects(:timeout).with(50) + it "should set a timeout for the download" do + Puppet::Configurer::Downloader.expects(:timeout).returns 50 + Timeout.expects(:timeout).with(50) - @dler.evaluate - end + @dler.evaluate + end - it "should apply the catalog within the timeout block" do - catalog = mock 'catalog' - @dler.expects(:catalog).returns(catalog) + it "should apply the catalog within the timeout block" do + catalog = mock 'catalog' + @dler.expects(:catalog).returns(catalog) - Timeout.expects(:timeout).yields + Timeout.expects(:timeout).yields - catalog.expects(:apply) + catalog.expects(:apply) - @dler.evaluate - end + @dler.evaluate + end - it "should return all changed file paths" do - trans = mock 'transaction' + it "should return all changed file paths" do + trans = mock 'transaction' - catalog = mock 'catalog' - @dler.expects(:catalog).returns(catalog) - catalog.expects(:apply).yields(trans) + catalog = mock 'catalog' + @dler.expects(:catalog).returns(catalog) + catalog.expects(:apply).yields(trans) - Timeout.expects(:timeout).yields + Timeout.expects(:timeout).yields - resource = mock 'resource' - resource.expects(:[]).with(:path).returns "/changed/file" + resource = mock 'resource' + resource.expects(:[]).with(:path).returns "/changed/file" - trans.expects(:changed?).returns([resource]) + trans.expects(:changed?).returns([resource]) - @dler.evaluate.should == %w{/changed/file} - end + @dler.evaluate.should == %w{/changed/file} + end - it "should yield the resources if a block is given" do - trans = mock 'transaction' + it "should yield the resources if a block is given" do + trans = mock 'transaction' - catalog = mock 'catalog' - @dler.expects(:catalog).returns(catalog) - catalog.expects(:apply).yields(trans) + catalog = mock 'catalog' + @dler.expects(:catalog).returns(catalog) + catalog.expects(:apply).yields(trans) - Timeout.expects(:timeout).yields + Timeout.expects(:timeout).yields - resource = mock 'resource' - resource.expects(:[]).with(:path).returns "/changed/file" + resource = mock 'resource' + resource.expects(:[]).with(:path).returns "/changed/file" - trans.expects(:changed?).returns([resource]) + trans.expects(:changed?).returns([resource]) - yielded = nil - @dler.evaluate { |r| yielded = r } - yielded.should == resource - end + yielded = nil + @dler.evaluate { |r| yielded = r } + yielded.should == resource + end - it "should catch and log exceptions" do - Puppet.expects(:err) - Timeout.stubs(:timeout).raises(Puppet::Error, "testing") + it "should catch and log exceptions" do + Puppet.expects(:err) + Timeout.stubs(:timeout).raises(Puppet::Error, "testing") - lambda { @dler.evaluate }.should_not raise_error - end + lambda { @dler.evaluate }.should_not raise_error end + end end diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb index 290f1acfc..051270144 100755 --- a/spec/unit/configurer/fact_handler_spec.rb +++ b/spec/unit/configurer/fact_handler_spec.rb @@ -5,160 +5,160 @@ require 'puppet/configurer' require 'puppet/configurer/fact_handler' class FactHandlerTester - include Puppet::Configurer::FactHandler + include Puppet::Configurer::FactHandler end describe Puppet::Configurer::FactHandler do - before do - @facthandler = FactHandlerTester.new - end + before do + @facthandler = FactHandlerTester.new + end - it "should have a method for downloading fact plugins" do - @facthandler.should respond_to(:download_fact_plugins) - end + it "should have a method for downloading fact plugins" do + @facthandler.should respond_to(:download_fact_plugins) + end - it "should have a boolean method for determining whether fact plugins should be downloaded" do - @facthandler.should respond_to(:download_fact_plugins?) - end + it "should have a boolean method for determining whether fact plugins should be downloaded" do + @facthandler.should respond_to(:download_fact_plugins?) + end - it "should download fact plugins when :factsync is true" do - Puppet.settings.expects(:value).with(:factsync).returns true - @facthandler.should be_download_fact_plugins - end + it "should download fact plugins when :factsync is true" do + Puppet.settings.expects(:value).with(:factsync).returns true + @facthandler.should be_download_fact_plugins + end - it "should not download fact plugins when :factsync is false" do - Puppet.settings.expects(:value).with(:factsync).returns false - @facthandler.should_not be_download_fact_plugins - end + it "should not download fact plugins when :factsync is false" do + Puppet.settings.expects(:value).with(:factsync).returns false + @facthandler.should_not be_download_fact_plugins + end - it "should not download fact plugins when downloading is disabled" do - Puppet::Configurer::Downloader.expects(:new).never - @facthandler.expects(:download_fact_plugins?).returns false - @facthandler.download_fact_plugins - end + it "should not download fact plugins when downloading is disabled" do + Puppet::Configurer::Downloader.expects(:new).never + @facthandler.expects(:download_fact_plugins?).returns false + @facthandler.download_fact_plugins + end - it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download fact plugins when downloading is enabled" do - downloader = mock 'downloader' + it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download fact plugins when downloading is enabled" do + downloader = mock 'downloader' - Puppet.settings.expects(:value).with(:factsource).returns "fsource" - Puppet.settings.expects(:value).with(:factdest).returns "fdest" - Puppet.settings.expects(:value).with(:factsignore).returns "fignore" + Puppet.settings.expects(:value).with(:factsource).returns "fsource" + Puppet.settings.expects(:value).with(:factdest).returns "fdest" + Puppet.settings.expects(:value).with(:factsignore).returns "fignore" - Puppet::Configurer::Downloader.expects(:new).with("fact", "fdest", "fsource", "fignore").returns downloader + Puppet::Configurer::Downloader.expects(:new).with("fact", "fdest", "fsource", "fignore").returns downloader - downloader.expects(:evaluate) + downloader.expects(:evaluate) - @facthandler.expects(:download_fact_plugins?).returns true - @facthandler.download_fact_plugins - end + @facthandler.expects(:download_fact_plugins?).returns true + @facthandler.download_fact_plugins + end - it "should warn about factsync deprecation when factsync is enabled" do - Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil) + it "should warn about factsync deprecation when factsync is enabled" do + Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil) - @facthandler.expects(:download_fact_plugins?).returns true - Puppet.expects(:warning) - @facthandler.download_fact_plugins - end + @facthandler.expects(:download_fact_plugins?).returns true + Puppet.expects(:warning) + @facthandler.download_fact_plugins + end - it "should have a method for retrieving facts" do - @facthandler.should respond_to(:find_facts) - end + it "should have a method for retrieving facts" do + @facthandler.should respond_to(:find_facts) + end - it "should use the Facts class with the :certname to find the facts" do - Puppet.settings.expects(:value).with(:certname).returns "foo" - Puppet::Node::Facts.expects(:find).with("foo").returns "myfacts" - @facthandler.stubs(:reload_facter) - @facthandler.find_facts.should == "myfacts" - end + it "should use the Facts class with the :certname to find the facts" do + Puppet.settings.expects(:value).with(:certname).returns "foo" + Puppet::Node::Facts.expects(:find).with("foo").returns "myfacts" + @facthandler.stubs(:reload_facter) + @facthandler.find_facts.should == "myfacts" + end - it "should reload Facter and find local facts when asked to find facts" do - @facthandler.expects(:reload_facter) + it "should reload Facter and find local facts when asked to find facts" do + @facthandler.expects(:reload_facter) - Puppet.settings.expects(:value).with(:certname).returns "myhost" - Puppet::Node::Facts.expects(:find).with("myhost") + Puppet.settings.expects(:value).with(:certname).returns "myhost" + Puppet::Node::Facts.expects(:find).with("myhost") - @facthandler.find_facts - end + @facthandler.find_facts + end - it "should fail if finding facts fails" do - @facthandler.stubs(:reload_facter) + it "should fail if finding facts fails" do + @facthandler.stubs(:reload_facter) - Puppet.settings.stubs(:value).with(:trace).returns false - Puppet.settings.stubs(:value).with(:certname).returns "myhost" - Puppet::Node::Facts.expects(:find).raises RuntimeError + Puppet.settings.stubs(:value).with(:trace).returns false + Puppet.settings.stubs(:value).with(:certname).returns "myhost" + Puppet::Node::Facts.expects(:find).raises RuntimeError - lambda { @facthandler.find_facts }.should raise_error(Puppet::Error) - end + lambda { @facthandler.find_facts }.should raise_error(Puppet::Error) + end - it "should have a method to prepare the facts for uploading" do - @facthandler.should respond_to(:facts_for_uploading) - end + it "should have a method to prepare the facts for uploading" do + @facthandler.should respond_to(:facts_for_uploading) + end - # I couldn't get marshal to work for this, only yaml, so we hard-code yaml. - it "should serialize and CGI escape the fact values for uploading" do - facts = stub 'facts' - facts.expects(:support_format?).with(:b64_zlib_yaml).returns true - facts.expects(:render).returns "my text" - text = CGI.escape("my text") + # I couldn't get marshal to work for this, only yaml, so we hard-code yaml. + it "should serialize and CGI escape the fact values for uploading" do + facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true + facts.expects(:render).returns "my text" + text = CGI.escape("my text") - @facthandler.expects(:find_facts).returns facts + @facthandler.expects(:find_facts).returns facts - @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text} - end + @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text} + end - it "should properly accept facts containing a '+'" do - facts = stub 'facts' - facts.expects(:support_format?).with(:b64_zlib_yaml).returns true - facts.expects(:render).returns "my+text" - text = "my%2Btext" + it "should properly accept facts containing a '+'" do + facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true + facts.expects(:render).returns "my+text" + text = "my%2Btext" - @facthandler.expects(:find_facts).returns facts + @facthandler.expects(:find_facts).returns facts - @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text} - end + @facthandler.facts_for_uploading.should == {:facts_format => :b64_zlib_yaml, :facts => text} + end - it "use compressed yaml as the serialization if zlib is supported" do - facts = stub 'facts' - facts.expects(:support_format?).with(:b64_zlib_yaml).returns true - facts.expects(:render).with(:b64_zlib_yaml).returns "my text" - text = CGI.escape("my text") + it "use compressed yaml as the serialization if zlib is supported" do + facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns true + facts.expects(:render).with(:b64_zlib_yaml).returns "my text" + text = CGI.escape("my text") - @facthandler.expects(:find_facts).returns facts + @facthandler.expects(:find_facts).returns facts - @facthandler.facts_for_uploading - end + @facthandler.facts_for_uploading + end + + it "should use yaml as the serialization if zlib is not supported" do + facts = stub 'facts' + facts.expects(:support_format?).with(:b64_zlib_yaml).returns false + facts.expects(:render).with(:yaml).returns "my text" + text = CGI.escape("my text") - it "should use yaml as the serialization if zlib is not supported" do - facts = stub 'facts' - facts.expects(:support_format?).with(:b64_zlib_yaml).returns false - facts.expects(:render).with(:yaml).returns "my text" - text = CGI.escape("my text") + @facthandler.expects(:find_facts).returns facts - @facthandler.expects(:find_facts).returns facts + @facthandler.facts_for_uploading + end + + describe "when reloading Facter" do + before do + Facter.stubs(:clear) + Facter.stubs(:load) + Facter.stubs(:loadfacts) + end + + it "should clear Facter" do + Facter.expects(:clear) + @facthandler.reload_facter + end - @facthandler.facts_for_uploading + it "should load all Facter facts" do + Facter.expects(:loadfacts) + @facthandler.reload_facter end - describe "when reloading Facter" do - before do - Facter.stubs(:clear) - Facter.stubs(:load) - Facter.stubs(:loadfacts) - end - - it "should clear Facter" do - Facter.expects(:clear) - @facthandler.reload_facter - end - - it "should load all Facter facts" do - Facter.expects(:loadfacts) - @facthandler.reload_facter - end - - it "should use the Facter terminus load all Puppet Fact plugins" do - Puppet::Node::Facts::Facter.expects(:load_fact_plugins) - @facthandler.reload_facter - end + it "should use the Facter terminus load all Puppet Fact plugins" do + Puppet::Node::Facts::Facter.expects(:load_fact_plugins) + @facthandler.reload_facter end + end end diff --git a/spec/unit/configurer/plugin_handler_spec.rb b/spec/unit/configurer/plugin_handler_spec.rb index 7f59d5bb3..25d2d47af 100755 --- a/spec/unit/configurer/plugin_handler_spec.rb +++ b/spec/unit/configurer/plugin_handler_spec.rb @@ -5,108 +5,108 @@ require 'puppet/configurer' require 'puppet/configurer/plugin_handler' class PluginHandlerTester - include Puppet::Configurer::PluginHandler + include Puppet::Configurer::PluginHandler end describe Puppet::Configurer::PluginHandler do - before do - @pluginhandler = PluginHandlerTester.new - end + before do + @pluginhandler = PluginHandlerTester.new + end - it "should have a method for downloading plugins" do - @pluginhandler.should respond_to(:download_plugins) - end + it "should have a method for downloading plugins" do + @pluginhandler.should respond_to(:download_plugins) + end - it "should have a boolean method for determining whether plugins should be downloaded" do - @pluginhandler.should respond_to(:download_plugins?) - end + it "should have a boolean method for determining whether plugins should be downloaded" do + @pluginhandler.should respond_to(:download_plugins?) + end - it "should download plugins when :pluginsync is true" do - Puppet.settings.expects(:value).with(:pluginsync).returns true - @pluginhandler.should be_download_plugins - end + it "should download plugins when :pluginsync is true" do + Puppet.settings.expects(:value).with(:pluginsync).returns true + @pluginhandler.should be_download_plugins + end - it "should not download plugins when :pluginsync is false" do - Puppet.settings.expects(:value).with(:pluginsync).returns false - @pluginhandler.should_not be_download_plugins - end + it "should not download plugins when :pluginsync is false" do + Puppet.settings.expects(:value).with(:pluginsync).returns false + @pluginhandler.should_not be_download_plugins + end - it "should not download plugins when downloading is disabled" do - Puppet::Configurer::Downloader.expects(:new).never - @pluginhandler.expects(:download_plugins?).returns false - @pluginhandler.download_plugins - end + it "should not download plugins when downloading is disabled" do + Puppet::Configurer::Downloader.expects(:new).never + @pluginhandler.expects(:download_plugins?).returns false + @pluginhandler.download_plugins + end - it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download plugins when downloading is enabled" do - downloader = mock 'downloader' + it "should use an Agent Downloader, with the name, source, destination, and ignore set correctly, to download plugins when downloading is enabled" do + downloader = mock 'downloader' - Puppet.settings.expects(:value).with(:pluginsource).returns "psource" - Puppet.settings.expects(:value).with(:plugindest).returns "pdest" - Puppet.settings.expects(:value).with(:pluginsignore).returns "pignore" + Puppet.settings.expects(:value).with(:pluginsource).returns "psource" + Puppet.settings.expects(:value).with(:plugindest).returns "pdest" + Puppet.settings.expects(:value).with(:pluginsignore).returns "pignore" - Puppet::Configurer::Downloader.expects(:new).with("plugin", "pdest", "psource", "pignore").returns downloader + Puppet::Configurer::Downloader.expects(:new).with("plugin", "pdest", "psource", "pignore").returns downloader - downloader.expects(:evaluate).returns [] + downloader.expects(:evaluate).returns [] - @pluginhandler.expects(:download_plugins?).returns true - @pluginhandler.download_plugins - end + @pluginhandler.expects(:download_plugins?).returns true + @pluginhandler.download_plugins + end - it "should be able to load plugins" do - @pluginhandler.should respond_to(:load_plugin) - end + it "should be able to load plugins" do + @pluginhandler.should respond_to(:load_plugin) + end - it "should load each downloaded file" do - FileTest.stubs(:exist?).returns true - downloader = mock 'downloader' + it "should load each downloaded file" do + FileTest.stubs(:exist?).returns true + downloader = mock 'downloader' - Puppet::Configurer::Downloader.expects(:new).returns downloader + Puppet::Configurer::Downloader.expects(:new).returns downloader - downloader.expects(:evaluate).returns %w{one two} + downloader.expects(:evaluate).returns %w{one two} - @pluginhandler.expects(:download_plugins?).returns true + @pluginhandler.expects(:download_plugins?).returns true - @pluginhandler.expects(:load_plugin).with("one") - @pluginhandler.expects(:load_plugin).with("two") + @pluginhandler.expects(:load_plugin).with("one") + @pluginhandler.expects(:load_plugin).with("two") - @pluginhandler.download_plugins - end + @pluginhandler.download_plugins + end - it "should load plugins when asked to do so" do - FileTest.stubs(:exist?).returns true - @pluginhandler.expects(:load).with("foo") + it "should load plugins when asked to do so" do + FileTest.stubs(:exist?).returns true + @pluginhandler.expects(:load).with("foo") - @pluginhandler.load_plugin("foo") - end + @pluginhandler.load_plugin("foo") + end - it "should not try to load files that don't exist" do - FileTest.expects(:exist?).with("foo").returns true - @pluginhandler.expects(:load).never + it "should not try to load files that don't exist" do + FileTest.expects(:exist?).with("foo").returns true + @pluginhandler.expects(:load).never - @pluginhandler.load_plugin("foo") - end + @pluginhandler.load_plugin("foo") + end - it "should not try to load directories" do - FileTest.stubs(:exist?).returns true - FileTest.expects(:directory?).with("foo").returns true - @pluginhandler.expects(:load).never + it "should not try to load directories" do + FileTest.stubs(:exist?).returns true + FileTest.expects(:directory?).with("foo").returns true + @pluginhandler.expects(:load).never - @pluginhandler.load_plugin("foo") - end + @pluginhandler.load_plugin("foo") + end - it "should warn but not fail if loading a file raises an exception" do - FileTest.stubs(:exist?).returns true - @pluginhandler.expects(:load).with("foo").raises "eh" + it "should warn but not fail if loading a file raises an exception" do + FileTest.stubs(:exist?).returns true + @pluginhandler.expects(:load).with("foo").raises "eh" - Puppet.expects(:err) - @pluginhandler.load_plugin("foo") - end + Puppet.expects(:err) + @pluginhandler.load_plugin("foo") + end - it "should warn but not fail if loading a file raises a LoadError" do - FileTest.stubs(:exist?).returns true - @pluginhandler.expects(:load).with("foo").raises LoadError.new("eh") + it "should warn but not fail if loading a file raises a LoadError" do + FileTest.stubs(:exist?).returns true + @pluginhandler.expects(:load).with("foo").raises LoadError.new("eh") - Puppet.expects(:err) - @pluginhandler.load_plugin("foo") - end + Puppet.expects(:err) + @pluginhandler.load_plugin("foo") + end end |