summaryrefslogtreecommitdiffstats
path: root/spec/unit/application/resource_spec.rb
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /spec/unit/application/resource_spec.rb
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-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/application/resource_spec.rb')
-rwxr-xr-xspec/unit/application/resource_spec.rb352
1 files changed, 176 insertions, 176 deletions
diff --git a/spec/unit/application/resource_spec.rb b/spec/unit/application/resource_spec.rb
index 71e35dc18..b6c52b11e 100755
--- a/spec/unit/application/resource_spec.rb
+++ b/spec/unit/application/resource_spec.rb
@@ -5,229 +5,229 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/application/resource'
describe Puppet::Application::Resource do
- before :each do
- @resource = Puppet::Application[:resource]
- Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:level=)
- Puppet::Resource.indirection.stubs(:terminus_class=)
+ before :each do
+ @resource = Puppet::Application[:resource]
+ Puppet::Util::Log.stubs(:newdestination)
+ Puppet::Util::Log.stubs(:level=)
+ Puppet::Resource.indirection.stubs(:terminus_class=)
+ end
+
+ it "should ask Puppet::Application to not parse Puppet configuration file" do
+ @resource.should_parse_config?.should be_false
+ end
+
+ it "should declare a main command" do
+ @resource.should respond_to(:main)
+ end
+
+ it "should declare a host option" do
+ @resource.should respond_to(:handle_host)
+ end
+
+ it "should declare a types option" do
+ @resource.should respond_to(:handle_types)
+ end
+
+ it "should declare a param option" do
+ @resource.should respond_to(:handle_param)
+ end
+
+ it "should declare a preinit block" do
+ @resource.should respond_to(:preinit)
+ end
+
+ describe "in preinit" do
+ it "should set hosts to nil" do
+ @resource.preinit
+
+ @resource.host.should be_nil
end
- it "should ask Puppet::Application to not parse Puppet configuration file" do
- @resource.should_parse_config?.should be_false
- end
+ it "should init extra_params to empty array" do
+ @resource.preinit
- it "should declare a main command" do
- @resource.should respond_to(:main)
+ @resource.extra_params.should == []
end
- it "should declare a host option" do
- @resource.should respond_to(:handle_host)
+ it "should load Facter facts" do
+ Facter.expects(:loadfacts).once
+ @resource.preinit
end
+ end
- it "should declare a types option" do
- @resource.should respond_to(:handle_types)
- end
+ describe "when handling options" do
- it "should declare a param option" do
- @resource.should respond_to(:handle_param)
- end
+ [:debug, :verbose, :edit].each do |option|
+ it "should declare handle_#{option} method" do
+ @resource.should respond_to("handle_#{option}".to_sym)
+ end
- it "should declare a preinit block" do
- @resource.should respond_to(:preinit)
+ it "should store argument value when calling handle_#{option}" do
+ @resource.options.expects(:[]=).with(option, 'arg')
+ @resource.send("handle_#{option}".to_sym, 'arg')
+ end
end
- describe "in preinit" do
- it "should set hosts to nil" do
- @resource.preinit
+ it "should set options[:host] to given host" do
+ @resource.handle_host(:whatever)
- @resource.host.should be_nil
- end
-
- it "should init extra_params to empty array" do
- @resource.preinit
-
- @resource.extra_params.should == []
- end
-
- it "should load Facter facts" do
- Facter.expects(:loadfacts).once
- @resource.preinit
- end
+ @resource.host.should == :whatever
end
- describe "when handling options" do
-
- [:debug, :verbose, :edit].each do |option|
- it "should declare handle_#{option} method" do
- @resource.should respond_to("handle_#{option}".to_sym)
- end
+ it "should load an display all types with types option" do
+ type1 = stub_everything 'type1', :name => :type1
+ type2 = stub_everything 'type2', :name => :type2
+ Puppet::Type.stubs(:loadall)
+ Puppet::Type.stubs(:eachtype).multiple_yields(type1,type2)
+ @resource.stubs(:exit)
- it "should store argument value when calling handle_#{option}" do
- @resource.options.expects(:[]=).with(option, 'arg')
- @resource.send("handle_#{option}".to_sym, 'arg')
- end
- end
-
- it "should set options[:host] to given host" do
- @resource.handle_host(:whatever)
-
- @resource.host.should == :whatever
- end
-
- it "should load an display all types with types option" do
- type1 = stub_everything 'type1', :name => :type1
- type2 = stub_everything 'type2', :name => :type2
- Puppet::Type.stubs(:loadall)
- Puppet::Type.stubs(:eachtype).multiple_yields(type1,type2)
- @resource.stubs(:exit)
-
- @resource.expects(:puts).with(['type1','type2'])
- @resource.handle_types(nil)
- end
-
- it "should add param to extra_params list" do
- @resource.extra_params = [ :param1 ]
- @resource.handle_param("whatever")
-
- @resource.extra_params.should == [ :param1, :whatever ]
- end
+ @resource.expects(:puts).with(['type1','type2'])
+ @resource.handle_types(nil)
end
- describe "during setup" do
- before :each do
- Puppet::Log.stubs(:newdestination)
- Puppet::Log.stubs(:level=)
- Puppet.stubs(:parse_config)
- end
-
+ it "should add param to extra_params list" do
+ @resource.extra_params = [ :param1 ]
+ @resource.handle_param("whatever")
- it "should set console as the log destination" do
- Puppet::Log.expects(:newdestination).with(:console)
-
- @resource.setup
- end
-
- it "should set log level to debug if --debug was passed" do
- @resource.options.stubs(:[]).with(:debug).returns(true)
+ @resource.extra_params.should == [ :param1, :whatever ]
+ end
+ end
- Puppet::Log.expects(:level=).with(:debug)
+ describe "during setup" do
+ before :each do
+ Puppet::Log.stubs(:newdestination)
+ Puppet::Log.stubs(:level=)
+ Puppet.stubs(:parse_config)
+ end
- @resource.setup
- end
- it "should set log level to info if --verbose was passed" do
- @resource.options.stubs(:[]).with(:debug).returns(false)
- @resource.options.stubs(:[]).with(:verbose).returns(true)
+ it "should set console as the log destination" do
+ Puppet::Log.expects(:newdestination).with(:console)
- Puppet::Log.expects(:level=).with(:info)
+ @resource.setup
+ end
- @resource.setup
- end
+ it "should set log level to debug if --debug was passed" do
+ @resource.options.stubs(:[]).with(:debug).returns(true)
- it "should Parse puppet config" do
- Puppet.expects(:parse_config)
+ Puppet::Log.expects(:level=).with(:debug)
- @resource.setup
- end
+ @resource.setup
end
- describe "when running" do
+ it "should set log level to info if --verbose was passed" do
+ @resource.options.stubs(:[]).with(:debug).returns(false)
+ @resource.options.stubs(:[]).with(:verbose).returns(true)
- before :each do
- @type = stub_everything 'type', :properties => []
- @resource.command_line.stubs(:args).returns(['type'])
- Puppet::Type.stubs(:type).returns(@type)
- end
+ Puppet::Log.expects(:level=).with(:info)
- it "should raise an error if no type is given" do
- @resource.command_line.stubs(:args).returns([])
- lambda { @resource.main }.should raise_error
- end
-
- it "should raise an error when editing a remote host" do
- @resource.options.stubs(:[]).with(:edit).returns(true)
- @resource.host = 'host'
+ @resource.setup
+ end
- lambda { @resource.main }.should raise_error
- end
+ it "should Parse puppet config" do
+ Puppet.expects(:parse_config)
- it "should raise an error if the type is not found" do
- Puppet::Type.stubs(:type).returns(nil)
+ @resource.setup
+ end
+ end
- lambda { @resource.main }.should raise_error
- end
+ describe "when running" do
- describe "with a host" do
- before :each do
- @resource.stubs(:puts)
- @resource.host = 'host'
+ before :each do
+ @type = stub_everything 'type', :properties => []
+ @resource.command_line.stubs(:args).returns(['type'])
+ Puppet::Type.stubs(:type).returns(@type)
+ end
- Puppet::Resource.stubs(:find ).never
- Puppet::Resource.stubs(:search).never
- Puppet::Resource.stubs(:save ).never
- end
+ it "should raise an error if no type is given" do
+ @resource.command_line.stubs(:args).returns([])
+ lambda { @resource.main }.should raise_error
+ end
- it "should search for resources" do
- @resource.command_line.stubs(:args).returns(['type'])
- Puppet::Resource.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([])
- @resource.main
- end
+ it "should raise an error when editing a remote host" do
+ @resource.options.stubs(:[]).with(:edit).returns(true)
+ @resource.host = 'host'
- it "should describe the given resource" do
- @resource.command_line.stubs(:args).returns(['type', 'name'])
- x = stub_everything 'resource'
- Puppet::Resource.expects(:find).with('https://host:8139/production/resources/type/name').returns(x)
- @resource.main
- end
+ lambda { @resource.main }.should raise_error
+ end
- it "should add given parameters to the object" do
- @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
+ it "should raise an error if the type is not found" do
+ Puppet::Type.stubs(:type).returns(nil)
- res = stub "resource"
- res.expects(:save).with('https://host:8139/production/resources/type/name').returns(res)
- res.expects(:collect)
- res.expects(:to_manifest)
- Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)
+ lambda { @resource.main }.should raise_error
+ end
- @resource.main
- end
+ describe "with a host" do
+ before :each do
+ @resource.stubs(:puts)
+ @resource.host = 'host'
+
+ Puppet::Resource.stubs(:find ).never
+ Puppet::Resource.stubs(:search).never
+ Puppet::Resource.stubs(:save ).never
+ end
+
+ it "should search for resources" do
+ @resource.command_line.stubs(:args).returns(['type'])
+ Puppet::Resource.expects(:search).with('https://host:8139/production/resources/type/', {}).returns([])
+ @resource.main
+ end
+
+ it "should describe the given resource" do
+ @resource.command_line.stubs(:args).returns(['type', 'name'])
+ x = stub_everything 'resource'
+ Puppet::Resource.expects(:find).with('https://host:8139/production/resources/type/name').returns(x)
+ @resource.main
+ end
+
+ it "should add given parameters to the object" do
+ @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
+
+ res = stub "resource"
+ res.expects(:save).with('https://host:8139/production/resources/type/name').returns(res)
+ res.expects(:collect)
+ res.expects(:to_manifest)
+ Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)
+
+ @resource.main
+ end
- end
+ end
- describe "without a host" do
- before :each do
- @resource.stubs(:puts)
- @resource.host = nil
+ describe "without a host" do
+ before :each do
+ @resource.stubs(:puts)
+ @resource.host = nil
- Puppet::Resource.stubs(:find ).never
- Puppet::Resource.stubs(:search).never
- Puppet::Resource.stubs(:save ).never
- end
+ Puppet::Resource.stubs(:find ).never
+ Puppet::Resource.stubs(:search).never
+ Puppet::Resource.stubs(:save ).never
+ end
- it "should search for resources" do
- Puppet::Resource.expects(:search).with('type/', {}).returns([])
- @resource.main
- end
+ it "should search for resources" do
+ Puppet::Resource.expects(:search).with('type/', {}).returns([])
+ @resource.main
+ end
- it "should describe the given resource" do
- @resource.command_line.stubs(:args).returns(['type','name'])
- x = stub_everything 'resource'
- Puppet::Resource.expects(:find).with('type/name').returns(x)
- @resource.main
- end
+ it "should describe the given resource" do
+ @resource.command_line.stubs(:args).returns(['type','name'])
+ x = stub_everything 'resource'
+ Puppet::Resource.expects(:find).with('type/name').returns(x)
+ @resource.main
+ end
- it "should add given parameters to the object" do
- @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
+ it "should add given parameters to the object" do
+ @resource.command_line.stubs(:args).returns(['type','name','param=temp'])
- res = stub "resource"
- res.expects(:save).with('type/name').returns(res)
- res.expects(:collect)
- res.expects(:to_manifest)
- Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)
+ res = stub "resource"
+ res.expects(:save).with('type/name').returns(res)
+ res.expects(:collect)
+ res.expects(:to_manifest)
+ Puppet::Resource.expects(:new).with('type', 'name', :parameters => {'param' => 'temp'}).returns(res)
- @resource.main
- end
+ @resource.main
+ end
- end
end
+ end
end