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/parameter | |
| 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/parameter')
| -rwxr-xr-x | spec/unit/parameter/value_collection_spec.rb | 250 | ||||
| -rwxr-xr-x | spec/unit/parameter/value_spec.rb | 144 |
2 files changed, 197 insertions, 197 deletions
diff --git a/spec/unit/parameter/value_collection_spec.rb b/spec/unit/parameter/value_collection_spec.rb index 421e5a2ea..78c2c5263 100755 --- a/spec/unit/parameter/value_collection_spec.rb +++ b/spec/unit/parameter/value_collection_spec.rb @@ -5,163 +5,163 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parameter' describe Puppet::Parameter::ValueCollection do - before do - @collection = Puppet::Parameter::ValueCollection.new - end + before do + @collection = Puppet::Parameter::ValueCollection.new + end + + it "should have a method for defining new values" do + @collection.should respond_to(:newvalues) + end + + it "should have a method for adding individual values" do + @collection.should respond_to(:newvalue) + end + + it "should be able to retrieve individual values" do + value = @collection.newvalue(:foo) + @collection.value(:foo).should equal(value) + end - it "should have a method for defining new values" do - @collection.should respond_to(:newvalues) - end + it "should be able to add an individual value with a block" do + @collection.newvalue(:foo) { raise "testing" } + @collection.value(:foo).block.should be_instance_of(Proc) + end - it "should have a method for adding individual values" do - @collection.should respond_to(:newvalue) - end + it "should be able to add values that are empty strings" do + lambda { @collection.newvalue('') }.should_not raise_error + end - it "should be able to retrieve individual values" do - value = @collection.newvalue(:foo) - @collection.value(:foo).should equal(value) - end + it "should be able to add values that are empty strings" do + value = @collection.newvalue('') + @collection.match?('').should equal(value) + end - it "should be able to add an individual value with a block" do - @collection.newvalue(:foo) { raise "testing" } - @collection.value(:foo).block.should be_instance_of(Proc) - end + it "should set :call to :none when adding a value with no block" do + value = @collection.newvalue(:foo) + value.call.should == :none + end - it "should be able to add values that are empty strings" do - lambda { @collection.newvalue('') }.should_not raise_error + describe "when adding a value with a block" do + it "should set the method name to 'set_' plus the value name" do + value = @collection.newvalue(:myval) { raise "testing" } + value.method.should == "set_myval" end + end - it "should be able to add values that are empty strings" do - value = @collection.newvalue('') - @collection.match?('').should equal(value) - end + it "should be able to add an individual value with options" do + value = @collection.newvalue(:foo, :call => :bar) + value.call.should == :bar + end - it "should set :call to :none when adding a value with no block" do - value = @collection.newvalue(:foo) - value.call.should == :none - end + it "should have a method for validating a value" do + @collection.should respond_to(:validate) + end - describe "when adding a value with a block" do - it "should set the method name to 'set_' plus the value name" do - value = @collection.newvalue(:myval) { raise "testing" } - value.method.should == "set_myval" - end - end + it "should have a method for munging a value" do + @collection.should respond_to(:munge) + end - it "should be able to add an individual value with options" do - value = @collection.newvalue(:foo, :call => :bar) - value.call.should == :bar - end + it "should be able to generate documentation when it has both values and regexes" do + @collection.newvalues :foo, "bar", %r{test} + @collection.doc.should be_instance_of(String) + end + + it "should correctly generate documentation for values" do + @collection.newvalues :foo + @collection.doc.should be_include("Valid values are ``foo``") + end + + it "should correctly generate documentation for regexes" do + @collection.newvalues %r{\w+} + @collection.doc.should be_include("Values can match ``/\\w+/``") + end + + it "should be able to find the first matching value" do + @collection.newvalues :foo, :bar + @collection.match?("foo").should be_instance_of(Puppet::Parameter::Value) + end + + it "should be able to match symbols" do + @collection.newvalues :foo, :bar + @collection.match?(:foo).should be_instance_of(Puppet::Parameter::Value) + end + + it "should be able to match symbols when a regex is provided" do + @collection.newvalues %r{.} + @collection.match?(:foo).should be_instance_of(Puppet::Parameter::Value) + end + + it "should be able to match values using regexes" do + @collection.newvalues %r{.} + @collection.match?("foo").should_not be_nil + end + + it "should prefer value matches to regex matches" do + @collection.newvalues %r{.}, :foo + @collection.match?("foo").name.should == :foo + end - it "should have a method for validating a value" do - @collection.should respond_to(:validate) + describe "when validating values" do + it "should do nothing if no values or regexes have been defined" do + @collection.validate("foo") end - it "should have a method for munging a value" do - @collection.should respond_to(:munge) + it "should fail if the value is not a defined value or alias and does not match a regex" do + @collection.newvalues :foo + lambda { @collection.validate("bar") }.should raise_error(ArgumentError) end - it "should be able to generate documentation when it has both values and regexes" do - @collection.newvalues :foo, "bar", %r{test} - @collection.doc.should be_instance_of(String) + it "should succeed if the value is one of the defined values" do + @collection.newvalues :foo + lambda { @collection.validate(:foo) }.should_not raise_error(ArgumentError) end - it "should correctly generate documentation for values" do - @collection.newvalues :foo - @collection.doc.should be_include("Valid values are ``foo``") + it "should succeed if the value is one of the defined values even if the definition uses a symbol and the validation uses a string" do + @collection.newvalues :foo + lambda { @collection.validate("foo") }.should_not raise_error(ArgumentError) end - it "should correctly generate documentation for regexes" do - @collection.newvalues %r{\w+} - @collection.doc.should be_include("Values can match ``/\\w+/``") + it "should succeed if the value is one of the defined values even if the definition uses a string and the validation uses a symbol" do + @collection.newvalues "foo" + lambda { @collection.validate(:foo) }.should_not raise_error(ArgumentError) end - it "should be able to find the first matching value" do - @collection.newvalues :foo, :bar - @collection.match?("foo").should be_instance_of(Puppet::Parameter::Value) + it "should succeed if the value is one of the defined aliases" do + @collection.newvalues :foo + @collection.aliasvalue :bar, :foo + lambda { @collection.validate("bar") }.should_not raise_error(ArgumentError) end - it "should be able to match symbols" do - @collection.newvalues :foo, :bar - @collection.match?(:foo).should be_instance_of(Puppet::Parameter::Value) + it "should succeed if the value matches one of the regexes" do + @collection.newvalues %r{\d} + lambda { @collection.validate("10") }.should_not raise_error(ArgumentError) end + end - it "should be able to match symbols when a regex is provided" do - @collection.newvalues %r{.} - @collection.match?(:foo).should be_instance_of(Puppet::Parameter::Value) + describe "when munging values" do + it "should do nothing if no values or regexes have been defined" do + @collection.munge("foo").should == "foo" end - it "should be able to match values using regexes" do - @collection.newvalues %r{.} - @collection.match?("foo").should_not be_nil + it "should return return any matching defined values" do + @collection.newvalues :foo, :bar + @collection.munge("foo").should == :foo end - it "should prefer value matches to regex matches" do - @collection.newvalues %r{.}, :foo - @collection.match?("foo").name.should == :foo + it "should return any matching aliases" do + @collection.newvalues :foo + @collection.aliasvalue :bar, :foo + @collection.munge("bar").should == :foo end - describe "when validating values" do - it "should do nothing if no values or regexes have been defined" do - @collection.validate("foo") - end - - it "should fail if the value is not a defined value or alias and does not match a regex" do - @collection.newvalues :foo - lambda { @collection.validate("bar") }.should raise_error(ArgumentError) - end - - it "should succeed if the value is one of the defined values" do - @collection.newvalues :foo - lambda { @collection.validate(:foo) }.should_not raise_error(ArgumentError) - end - - it "should succeed if the value is one of the defined values even if the definition uses a symbol and the validation uses a string" do - @collection.newvalues :foo - lambda { @collection.validate("foo") }.should_not raise_error(ArgumentError) - end - - it "should succeed if the value is one of the defined values even if the definition uses a string and the validation uses a symbol" do - @collection.newvalues "foo" - lambda { @collection.validate(:foo) }.should_not raise_error(ArgumentError) - end - - it "should succeed if the value is one of the defined aliases" do - @collection.newvalues :foo - @collection.aliasvalue :bar, :foo - lambda { @collection.validate("bar") }.should_not raise_error(ArgumentError) - end - - it "should succeed if the value matches one of the regexes" do - @collection.newvalues %r{\d} - lambda { @collection.validate("10") }.should_not raise_error(ArgumentError) - end + it "should return the value if it matches a regex" do + @collection.newvalues %r{\w} + @collection.munge("bar").should == "bar" end - describe "when munging values" do - it "should do nothing if no values or regexes have been defined" do - @collection.munge("foo").should == "foo" - end - - it "should return return any matching defined values" do - @collection.newvalues :foo, :bar - @collection.munge("foo").should == :foo - end - - it "should return any matching aliases" do - @collection.newvalues :foo - @collection.aliasvalue :bar, :foo - @collection.munge("bar").should == :foo - end - - it "should return the value if it matches a regex" do - @collection.newvalues %r{\w} - @collection.munge("bar").should == "bar" - end - - it "should return the value if no other option is matched" do - @collection.newvalues :foo - @collection.munge("bar").should == "bar" - end + it "should return the value if no other option is matched" do + @collection.newvalues :foo + @collection.munge("bar").should == "bar" end + end end diff --git a/spec/unit/parameter/value_spec.rb b/spec/unit/parameter/value_spec.rb index f6def01dd..10b24fb4d 100755 --- a/spec/unit/parameter/value_spec.rb +++ b/spec/unit/parameter/value_spec.rb @@ -5,84 +5,84 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parameter' describe Puppet::Parameter::Value do - it "should require a name" do - lambda { Puppet::Parameter::Value.new }.should raise_error(ArgumentError) + it "should require a name" do + lambda { Puppet::Parameter::Value.new }.should raise_error(ArgumentError) + end + + it "should set its name" do + Puppet::Parameter::Value.new(:foo).name.should == :foo + end + + it "should support regexes as names" do + lambda { Puppet::Parameter::Value.new(%r{foo}) }.should_not raise_error + end + + it "should mark itself as a regex if its name is a regex" do + Puppet::Parameter::Value.new(%r{foo}).should be_regex + end + + it "should always convert its name to a symbol if it is not a regex" do + Puppet::Parameter::Value.new("foo").name.should == :foo + Puppet::Parameter::Value.new(true).name.should == :true + end + + it "should support adding aliases" do + Puppet::Parameter::Value.new("foo").should respond_to(:alias) + end + + it "should be able to return its aliases" do + value = Puppet::Parameter::Value.new("foo") + value.alias("bar") + value.alias("baz") + value.aliases.should == [:bar, :baz] + end + + [:block, :call, :method, :event, :required_features].each do |attr| + it "should support a #{attr} attribute" do + value = Puppet::Parameter::Value.new("foo") + value.should respond_to(attr.to_s + "=") + value.should respond_to(attr) end - - it "should set its name" do - Puppet::Parameter::Value.new(:foo).name.should == :foo - end - - it "should support regexes as names" do - lambda { Puppet::Parameter::Value.new(%r{foo}) }.should_not raise_error - end - - it "should mark itself as a regex if its name is a regex" do - Puppet::Parameter::Value.new(%r{foo}).should be_regex + end + + it "should default to :instead for :call if a block is provided" do + Puppet::Parameter::Value.new("foo").call.should == :instead + end + + it "should always return events as symbols" do + value = Puppet::Parameter::Value.new("foo") + value.event = "foo_test" + value.event.should == :foo_test + end + + describe "when matching" do + describe "a regex" do + it "should return true if the regex matches the value" do + Puppet::Parameter::Value.new(/\w/).should be_match("foo") + end + + it "should return false if the regex does not match the value" do + Puppet::Parameter::Value.new(/\d/).should_not be_match("foo") + end end - it "should always convert its name to a symbol if it is not a regex" do - Puppet::Parameter::Value.new("foo").name.should == :foo - Puppet::Parameter::Value.new(true).name.should == :true - end + describe "a non-regex" do + it "should return true if the value, converted to a symbol, matches the name" do + Puppet::Parameter::Value.new("foo").should be_match("foo") + Puppet::Parameter::Value.new(:foo).should be_match(:foo) + Puppet::Parameter::Value.new(:foo).should be_match("foo") + Puppet::Parameter::Value.new("foo").should be_match(:foo) + end - it "should support adding aliases" do - Puppet::Parameter::Value.new("foo").should respond_to(:alias) - end + it "should return false if the value, converted to a symbol, does not match the name" do + Puppet::Parameter::Value.new(:foo).should_not be_match(:bar) + end - it "should be able to return its aliases" do + it "should return true if any of its aliases match" do value = Puppet::Parameter::Value.new("foo") value.alias("bar") - value.alias("baz") - value.aliases.should == [:bar, :baz] - end - - [:block, :call, :method, :event, :required_features].each do |attr| - it "should support a #{attr} attribute" do - value = Puppet::Parameter::Value.new("foo") - value.should respond_to(attr.to_s + "=") - value.should respond_to(attr) - end - end - - it "should default to :instead for :call if a block is provided" do - Puppet::Parameter::Value.new("foo").call.should == :instead - end - - it "should always return events as symbols" do - value = Puppet::Parameter::Value.new("foo") - value.event = "foo_test" - value.event.should == :foo_test - end - - describe "when matching" do - describe "a regex" do - it "should return true if the regex matches the value" do - Puppet::Parameter::Value.new(/\w/).should be_match("foo") - end - - it "should return false if the regex does not match the value" do - Puppet::Parameter::Value.new(/\d/).should_not be_match("foo") - end - end - - describe "a non-regex" do - it "should return true if the value, converted to a symbol, matches the name" do - Puppet::Parameter::Value.new("foo").should be_match("foo") - Puppet::Parameter::Value.new(:foo).should be_match(:foo) - Puppet::Parameter::Value.new(:foo).should be_match("foo") - Puppet::Parameter::Value.new("foo").should be_match(:foo) - end - - it "should return false if the value, converted to a symbol, does not match the name" do - Puppet::Parameter::Value.new(:foo).should_not be_match(:bar) - end - - it "should return true if any of its aliases match" do - value = Puppet::Parameter::Value.new("foo") - value.alias("bar") - value.should be_match("bar") - end - end + value.should be_match("bar") + end end + end end |
