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/provider/confine | |
| 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/provider/confine')
| -rwxr-xr-x | spec/unit/provider/confine/exists_spec.rb | 124 | ||||
| -rwxr-xr-x | spec/unit/provider/confine/false_spec.rb | 72 | ||||
| -rwxr-xr-x | spec/unit/provider/confine/feature_spec.rb | 84 | ||||
| -rwxr-xr-x | spec/unit/provider/confine/true_spec.rb | 70 | ||||
| -rwxr-xr-x | spec/unit/provider/confine/variable_spec.rb | 176 |
5 files changed, 263 insertions, 263 deletions
diff --git a/spec/unit/provider/confine/exists_spec.rb b/spec/unit/provider/confine/exists_spec.rb index a3539c4f5..c3958e317 100755 --- a/spec/unit/provider/confine/exists_spec.rb +++ b/spec/unit/provider/confine/exists_spec.rb @@ -5,77 +5,77 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/provider/confine/exists' describe Puppet::Provider::Confine::Exists do - before do - @confine = Puppet::Provider::Confine::Exists.new("/my/file") - @confine.label = "eh" + before do + @confine = Puppet::Provider::Confine::Exists.new("/my/file") + @confine.label = "eh" + end + + it "should be named :exists" do + Puppet::Provider::Confine::Exists.name.should == :exists + end + + it "should use the 'pass?' method to test validity" do + @confine.expects(:pass?).with("/my/file") + @confine.valid? + end + + it "should return false if the value is false" do + @confine.pass?(false).should be_false + end + + it "should return false if the value does not point to a file" do + FileTest.expects(:exist?).with("/my/file").returns false + @confine.pass?("/my/file").should be_false + end + + it "should return true if the value points to a file" do + FileTest.expects(:exist?).with("/my/file").returns true + @confine.pass?("/my/file").should be_true + end + + it "should produce a message saying that a file is missing" do + @confine.message("/my/file").should be_include("does not exist") + end + + describe "and the confine is for binaries" do + before { @confine.stubs(:for_binary).returns true } + it "should use its 'binary' method to look up the full path of the file" do + @confine.expects(:binary).returns nil + @confine.pass?("/my/file") end - it "should be named :exists" do - Puppet::Provider::Confine::Exists.name.should == :exists + it "should return false if no binary can be found" do + @confine.expects(:binary).with("/my/file").returns nil + @confine.pass?("/my/file").should be_false end - it "should use the 'pass?' method to test validity" do - @confine.expects(:pass?).with("/my/file") - @confine.valid? + it "should return true if the binary can be found and the file exists" do + @confine.expects(:binary).with("/my/file").returns "/my/file" + FileTest.expects(:exist?).with("/my/file").returns true + @confine.pass?("/my/file").should be_true end - it "should return false if the value is false" do - @confine.pass?(false).should be_false + it "should return false if the binary can be found but the file does not exist" do + @confine.expects(:binary).with("/my/file").returns "/my/file" + FileTest.expects(:exist?).with("/my/file").returns true + @confine.pass?("/my/file").should be_true end + end - it "should return false if the value does not point to a file" do - FileTest.expects(:exist?).with("/my/file").returns false - @confine.pass?("/my/file").should be_false - end - - it "should return true if the value points to a file" do - FileTest.expects(:exist?).with("/my/file").returns true - @confine.pass?("/my/file").should be_true - end - - it "should produce a message saying that a file is missing" do - @confine.message("/my/file").should be_include("does not exist") - end + it "should produce a summary containing all missing files" do + FileTest.stubs(:exist?).returns true + FileTest.expects(:exist?).with("/two").returns false + FileTest.expects(:exist?).with("/four").returns false - describe "and the confine is for binaries" do - before { @confine.stubs(:for_binary).returns true } - it "should use its 'binary' method to look up the full path of the file" do - @confine.expects(:binary).returns nil - @confine.pass?("/my/file") - end - - it "should return false if no binary can be found" do - @confine.expects(:binary).with("/my/file").returns nil - @confine.pass?("/my/file").should be_false - end - - it "should return true if the binary can be found and the file exists" do - @confine.expects(:binary).with("/my/file").returns "/my/file" - FileTest.expects(:exist?).with("/my/file").returns true - @confine.pass?("/my/file").should be_true - end - - it "should return false if the binary can be found but the file does not exist" do - @confine.expects(:binary).with("/my/file").returns "/my/file" - FileTest.expects(:exist?).with("/my/file").returns true - @confine.pass?("/my/file").should be_true - end - end - - it "should produce a summary containing all missing files" do - FileTest.stubs(:exist?).returns true - FileTest.expects(:exist?).with("/two").returns false - FileTest.expects(:exist?).with("/four").returns false + confine = Puppet::Provider::Confine::Exists.new %w{/one /two /three /four} + confine.summary.should == %w{/two /four} + end - confine = Puppet::Provider::Confine::Exists.new %w{/one /two /three /four} - confine.summary.should == %w{/two /four} - end + it "should summarize multiple instances by returning a flattened array of their summaries" do + c1 = mock '1', :summary => %w{one} + c2 = mock '2', :summary => %w{two} + c3 = mock '3', :summary => %w{three} - it "should summarize multiple instances by returning a flattened array of their summaries" do - c1 = mock '1', :summary => %w{one} - c2 = mock '2', :summary => %w{two} - c3 = mock '3', :summary => %w{three} - - Puppet::Provider::Confine::Exists.summarize([c1, c2, c3]).should == %w{one two three} - end + Puppet::Provider::Confine::Exists.summarize([c1, c2, c3]).should == %w{one two three} + end end diff --git a/spec/unit/provider/confine/false_spec.rb b/spec/unit/provider/confine/false_spec.rb index 425aa3077..999fc4714 100755 --- a/spec/unit/provider/confine/false_spec.rb +++ b/spec/unit/provider/confine/false_spec.rb @@ -5,49 +5,49 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/provider/confine/false' describe Puppet::Provider::Confine::False do - it "should be named :false" do - Puppet::Provider::Confine::False.name.should == :false + it "should be named :false" do + Puppet::Provider::Confine::False.name.should == :false + end + + it "should require a value" do + lambda { Puppet::Provider::Confine.new }.should raise_error(ArgumentError) + end + + describe "when testing values" do + before { @confine = Puppet::Provider::Confine::False.new("foo") } + + it "should use the 'pass?' method to test validity" do + @confine = Puppet::Provider::Confine::False.new("foo") + @confine.label = "eh" + @confine.expects(:pass?).with("foo") + @confine.valid? end - it "should require a value" do - lambda { Puppet::Provider::Confine.new }.should raise_error(ArgumentError) + it "should return true if the value is false" do + @confine.pass?(false).should be_true end - describe "when testing values" do - before { @confine = Puppet::Provider::Confine::False.new("foo") } - - it "should use the 'pass?' method to test validity" do - @confine = Puppet::Provider::Confine::False.new("foo") - @confine.label = "eh" - @confine.expects(:pass?).with("foo") - @confine.valid? - end - - it "should return true if the value is false" do - @confine.pass?(false).should be_true - end - - it "should return false if the value is not false" do - @confine.pass?("else").should be_false - end - - it "should produce a message that a value is true" do - @confine = Puppet::Provider::Confine::False.new("foo") - @confine.message("eh").should be_include("true") - end + it "should return false if the value is not false" do + @confine.pass?("else").should be_false end - it "should be able to produce a summary with the number of incorrectly true values" do - confine = Puppet::Provider::Confine::False.new %w{one two three four} - confine.expects(:pass?).times(4).returns(true).returns(false).returns(true).returns(false) - confine.summary.should == 2 + it "should produce a message that a value is true" do + @confine = Puppet::Provider::Confine::False.new("foo") + @confine.message("eh").should be_include("true") end + end - it "should summarize multiple instances by summing their summaries" do - c1 = mock '1', :summary => 1 - c2 = mock '2', :summary => 2 - c3 = mock '3', :summary => 3 + it "should be able to produce a summary with the number of incorrectly true values" do + confine = Puppet::Provider::Confine::False.new %w{one two three four} + confine.expects(:pass?).times(4).returns(true).returns(false).returns(true).returns(false) + confine.summary.should == 2 + end - Puppet::Provider::Confine::False.summarize([c1, c2, c3]).should == 6 - end + it "should summarize multiple instances by summing their summaries" do + c1 = mock '1', :summary => 1 + c2 = mock '2', :summary => 2 + c3 = mock '3', :summary => 3 + + Puppet::Provider::Confine::False.summarize([c1, c2, c3]).should == 6 + end end diff --git a/spec/unit/provider/confine/feature_spec.rb b/spec/unit/provider/confine/feature_spec.rb index 1db81ba44..e8368efac 100755 --- a/spec/unit/provider/confine/feature_spec.rb +++ b/spec/unit/provider/confine/feature_spec.rb @@ -5,56 +5,56 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/provider/confine/feature' describe Puppet::Provider::Confine::Feature do - it "should be named :feature" do - Puppet::Provider::Confine::Feature.name.should == :feature + it "should be named :feature" do + Puppet::Provider::Confine::Feature.name.should == :feature + end + + it "should require a value" do + lambda { Puppet::Provider::Confine::Feature.new }.should raise_error(ArgumentError) + end + + it "should always convert values to an array" do + Puppet::Provider::Confine::Feature.new("/some/file").values.should be_instance_of(Array) + end + + describe "when testing values" do + before do + @features = mock 'features' + Puppet.stubs(:features).returns @features + @confine = Puppet::Provider::Confine::Feature.new("myfeature") + @confine.label = "eh" end - it "should require a value" do - lambda { Puppet::Provider::Confine::Feature.new }.should raise_error(ArgumentError) + it "should use the Puppet features instance to test validity" do + @features.expects(:myfeature?) + @confine.valid? end - it "should always convert values to an array" do - Puppet::Provider::Confine::Feature.new("/some/file").values.should be_instance_of(Array) + it "should return true if the feature is present" do + @features.expects(:myfeature?).returns true + @confine.pass?("myfeature").should be_true end - describe "when testing values" do - before do - @features = mock 'features' - Puppet.stubs(:features).returns @features - @confine = Puppet::Provider::Confine::Feature.new("myfeature") - @confine.label = "eh" - end - - it "should use the Puppet features instance to test validity" do - @features.expects(:myfeature?) - @confine.valid? - end - - it "should return true if the feature is present" do - @features.expects(:myfeature?).returns true - @confine.pass?("myfeature").should be_true - end - - it "should return false if the value is false" do - @features.expects(:myfeature?).returns false - @confine.pass?("myfeature").should be_false - end - - it "should log that a feature is missing" do - @confine.message("myfeat").should be_include("missing") - end + it "should return false if the value is false" do + @features.expects(:myfeature?).returns false + @confine.pass?("myfeature").should be_false end - it "should summarize multiple instances by returning a flattened array of all missing features" do - confines = [] - confines << Puppet::Provider::Confine::Feature.new(%w{one two}) - confines << Puppet::Provider::Confine::Feature.new(%w{two}) - confines << Puppet::Provider::Confine::Feature.new(%w{three four}) + it "should log that a feature is missing" do + @confine.message("myfeat").should be_include("missing") + end + end - features = mock 'feature' - features.stub_everything - Puppet.stubs(:features).returns features + it "should summarize multiple instances by returning a flattened array of all missing features" do + confines = [] + confines << Puppet::Provider::Confine::Feature.new(%w{one two}) + confines << Puppet::Provider::Confine::Feature.new(%w{two}) + confines << Puppet::Provider::Confine::Feature.new(%w{three four}) - Puppet::Provider::Confine::Feature.summarize(confines).sort.should == %w{one two three four}.sort - end + features = mock 'feature' + features.stub_everything + Puppet.stubs(:features).returns features + + Puppet::Provider::Confine::Feature.summarize(confines).sort.should == %w{one two three four}.sort + end end diff --git a/spec/unit/provider/confine/true_spec.rb b/spec/unit/provider/confine/true_spec.rb index 2675afe75..23041e6d5 100755 --- a/spec/unit/provider/confine/true_spec.rb +++ b/spec/unit/provider/confine/true_spec.rb @@ -5,49 +5,49 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/provider/confine/true' describe Puppet::Provider::Confine::True do - it "should be named :true" do - Puppet::Provider::Confine::True.name.should == :true + it "should be named :true" do + Puppet::Provider::Confine::True.name.should == :true + end + + it "should require a value" do + lambda { Puppet::Provider::Confine::True.new }.should raise_error(ArgumentError) + end + + describe "when testing values" do + before do + @confine = Puppet::Provider::Confine::True.new("foo") + @confine.label = "eh" end - it "should require a value" do - lambda { Puppet::Provider::Confine::True.new }.should raise_error(ArgumentError) + it "should use the 'pass?' method to test validity" do + @confine.expects(:pass?).with("foo") + @confine.valid? end - describe "when testing values" do - before do - @confine = Puppet::Provider::Confine::True.new("foo") - @confine.label = "eh" - end - - it "should use the 'pass?' method to test validity" do - @confine.expects(:pass?).with("foo") - @confine.valid? - end - - it "should return true if the value is not false" do - @confine.pass?("else").should be_true - end - - it "should return false if the value is false" do - @confine.pass?(nil).should be_false - end + it "should return true if the value is not false" do + @confine.pass?("else").should be_true + end - it "should produce the message that a value is false" do - @confine.message("eh").should be_include("false") - end + it "should return false if the value is false" do + @confine.pass?(nil).should be_false end - it "should produce the number of false values when asked for a summary" do - @confine = Puppet::Provider::Confine::True.new %w{one two three four} - @confine.expects(:pass?).times(4).returns(true).returns(false).returns(true).returns(false) - @confine.summary.should == 2 + it "should produce the message that a value is false" do + @confine.message("eh").should be_include("false") end + end - it "should summarize multiple instances by summing their summaries" do - c1 = mock '1', :summary => 1 - c2 = mock '2', :summary => 2 - c3 = mock '3', :summary => 3 + it "should produce the number of false values when asked for a summary" do + @confine = Puppet::Provider::Confine::True.new %w{one two three four} + @confine.expects(:pass?).times(4).returns(true).returns(false).returns(true).returns(false) + @confine.summary.should == 2 + end - Puppet::Provider::Confine::True.summarize([c1, c2, c3]).should == 6 - end + it "should summarize multiple instances by summing their summaries" do + c1 = mock '1', :summary => 1 + c2 = mock '2', :summary => 2 + c3 = mock '3', :summary => 3 + + Puppet::Provider::Confine::True.summarize([c1, c2, c3]).should == 6 + end end diff --git a/spec/unit/provider/confine/variable_spec.rb b/spec/unit/provider/confine/variable_spec.rb index e554ac036..eda2dd4c5 100755 --- a/spec/unit/provider/confine/variable_spec.rb +++ b/spec/unit/provider/confine/variable_spec.rb @@ -5,103 +5,103 @@ require File.dirname(__FILE__) + '/../../../spec_helper' require 'puppet/provider/confine/variable' describe Puppet::Provider::Confine::Variable do - it "should be named :variable" do - Puppet::Provider::Confine::Variable.name.should == :variable + it "should be named :variable" do + Puppet::Provider::Confine::Variable.name.should == :variable + end + + it "should require a value" do + lambda { Puppet::Provider::Confine::Variable.new }.should raise_error(ArgumentError) + end + + it "should always convert values to an array" do + Puppet::Provider::Confine::Variable.new("/some/file").values.should be_instance_of(Array) + end + + it "should have an accessor for its name" do + Puppet::Provider::Confine::Variable.new(:bar).should respond_to(:name) + end + + describe "when testing values" do + before do + @confine = Puppet::Provider::Confine::Variable.new("foo") + @confine.name = :myvar end - it "should require a value" do - lambda { Puppet::Provider::Confine::Variable.new }.should raise_error(ArgumentError) + it "should use settings if the variable name is a valid setting" do + Puppet.settings.expects(:valid?).with(:myvar).returns true + Puppet.settings.expects(:value).with(:myvar).returns "foo" + @confine.valid? end - it "should always convert values to an array" do - Puppet::Provider::Confine::Variable.new("/some/file").values.should be_instance_of(Array) + it "should use Facter if the variable name is not a valid setting" do + Puppet.settings.expects(:valid?).with(:myvar).returns false + Facter.expects(:value).with(:myvar).returns "foo" + @confine.valid? end - it "should have an accessor for its name" do - Puppet::Provider::Confine::Variable.new(:bar).should respond_to(:name) + it "should be valid if the value matches the facter value" do + @confine.expects(:test_value).returns "foo" + + @confine.should be_valid + end + + it "should return false if the value does not match the facter value" do + @confine.expects(:test_value).returns "fee" + + @confine.should_not be_valid + end + + it "should be case insensitive" do + @confine.expects(:test_value).returns "FOO" + + @confine.should be_valid end - describe "when testing values" do - before do - @confine = Puppet::Provider::Confine::Variable.new("foo") - @confine.name = :myvar - end - - it "should use settings if the variable name is a valid setting" do - Puppet.settings.expects(:valid?).with(:myvar).returns true - Puppet.settings.expects(:value).with(:myvar).returns "foo" - @confine.valid? - end - - it "should use Facter if the variable name is not a valid setting" do - Puppet.settings.expects(:valid?).with(:myvar).returns false - Facter.expects(:value).with(:myvar).returns "foo" - @confine.valid? - end - - it "should be valid if the value matches the facter value" do - @confine.expects(:test_value).returns "foo" - - @confine.should be_valid - end - - it "should return false if the value does not match the facter value" do - @confine.expects(:test_value).returns "fee" - - @confine.should_not be_valid - end - - it "should be case insensitive" do - @confine.expects(:test_value).returns "FOO" - - @confine.should be_valid - end - - it "should not care whether the value is a string or symbol" do - @confine.expects(:test_value).returns "FOO" - - @confine.should be_valid - end - - it "should produce a message that the fact value is not correct" do - @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee}) - @confine.name = "eh" - message = @confine.message("value") - message.should be_include("facter") - message.should be_include("bar,bee") - end - - it "should be valid if the test value matches any of the provided values" do - @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee}) - @confine.expects(:test_value).returns "bee" - @confine.should be_valid - end + it "should not care whether the value is a string or symbol" do + @confine.expects(:test_value).returns "FOO" + + @confine.should be_valid + end + + it "should produce a message that the fact value is not correct" do + @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee}) + @confine.name = "eh" + message = @confine.message("value") + message.should be_include("facter") + message.should be_include("bar,bee") end - describe "when summarizing multiple instances" do - it "should return a hash of failing variables and their values" do - c1 = Puppet::Provider::Confine::Variable.new("one") - c1.name = "uno" - c1.expects(:valid?).returns false - c2 = Puppet::Provider::Confine::Variable.new("two") - c2.name = "dos" - c2.expects(:valid?).returns true - c3 = Puppet::Provider::Confine::Variable.new("three") - c3.name = "tres" - c3.expects(:valid?).returns false - - Puppet::Provider::Confine::Variable.summarize([c1, c2, c3]).should == {"uno" => %w{one}, "tres" => %w{three}} - end - - it "should combine the values of multiple confines with the same fact" do - c1 = Puppet::Provider::Confine::Variable.new("one") - c1.name = "uno" - c1.expects(:valid?).returns false - c2 = Puppet::Provider::Confine::Variable.new("two") - c2.name = "uno" - c2.expects(:valid?).returns false - - Puppet::Provider::Confine::Variable.summarize([c1, c2]).should == {"uno" => %w{one two}} - end + it "should be valid if the test value matches any of the provided values" do + @confine = Puppet::Provider::Confine::Variable.new(%w{bar bee}) + @confine.expects(:test_value).returns "bee" + @confine.should be_valid + end + end + + describe "when summarizing multiple instances" do + it "should return a hash of failing variables and their values" do + c1 = Puppet::Provider::Confine::Variable.new("one") + c1.name = "uno" + c1.expects(:valid?).returns false + c2 = Puppet::Provider::Confine::Variable.new("two") + c2.name = "dos" + c2.expects(:valid?).returns true + c3 = Puppet::Provider::Confine::Variable.new("three") + c3.name = "tres" + c3.expects(:valid?).returns false + + Puppet::Provider::Confine::Variable.summarize([c1, c2, c3]).should == {"uno" => %w{one}, "tres" => %w{three}} + end + + it "should combine the values of multiple confines with the same fact" do + c1 = Puppet::Provider::Confine::Variable.new("one") + c1.name = "uno" + c1.expects(:valid?).returns false + c2 = Puppet::Provider::Confine::Variable.new("two") + c2.name = "uno" + c2.expects(:valid?).returns false + + Puppet::Provider::Confine::Variable.summarize([c1, c2]).should == {"uno" => %w{one two}} end + end end |
