diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
| commit | 8d1fbe4586c91682cdda0cb271649e918fd9778b (patch) | |
| tree | 314508ca21830874d9e4ec6e27880fede14193bd /test/ral | |
| parent | 889158ad57e33df083613d6f7d136b2e11aaa16a (diff) | |
| download | puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.gz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.xz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.zip | |
Code smell: Avoid explicit returns
Replaced 583 occurances of
(DEF)
(LINES)
return (.*)
end
with
3 Examples:
The code:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
return filters
end
becomes:
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
end
filters
end
The code:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return return_value
end
becomes:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return_value
end
The code:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
return fakefile(File::join("data/types/mount", name))
end
becomes:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
fakefile(File::join("data/types/mount", name))
end
Diffstat (limited to 'test/ral')
| -rwxr-xr-x | test/ral/manager/attributes.rb | 2 | ||||
| -rwxr-xr-x | test/ral/manager/type.rb | 4 | ||||
| -rwxr-xr-x | test/ral/providers/group.rb | 6 | ||||
| -rwxr-xr-x | test/ral/providers/host/parsed.rb | 2 | ||||
| -rwxr-xr-x | test/ral/providers/mailalias/aliases.rb | 2 | ||||
| -rwxr-xr-x | test/ral/providers/package.rb | 2 | ||||
| -rwxr-xr-x | test/ral/providers/provider.rb | 4 | ||||
| -rwxr-xr-x | test/ral/providers/sshkey/parsed.rb | 2 | ||||
| -rwxr-xr-x | test/ral/providers/user.rb | 6 | ||||
| -rwxr-xr-x | test/ral/type/cron.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/file.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/filesources.rb | 4 | ||||
| -rwxr-xr-x | test/ral/type/host.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/sshkey.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/user.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/yumrepo.rb | 2 | ||||
| -rwxr-xr-x | test/ral/type/zone.rb | 2 |
17 files changed, 24 insertions, 24 deletions
diff --git a/test/ral/manager/attributes.rb b/test/ral/manager/attributes.rb index 95a077620..24edf37dc 100755 --- a/test/ral/manager/attributes.rb +++ b/test/ral/manager/attributes.rb @@ -276,7 +276,7 @@ class TestTypeAttributes < Test::Unit::TestCase $yep = :absent type.provide(:only) do def self.supports_parameter?(param) - return param.name != :nope + param.name != :nope end def yep diff --git a/test/ral/manager/type.rb b/test/ral/manager/type.rb index 9182dab09..5190bc7c7 100755 --- a/test/ral/manager/type.rb +++ b/test/ral/manager/type.rb @@ -177,10 +177,10 @@ class TestType < Test::Unit::TestCase # Create a type with a fake provider providerclass = Class.new do def self.supports_parameter?(prop) - return true + true end def method_missing(method, *args) - return method + method end end self.class.const_set("ProviderClass", providerclass) diff --git a/test/ral/providers/group.rb b/test/ral/providers/group.rb index 6a0d20268..48120f332 100755 --- a/test/ral/providers/group.rb +++ b/test/ral/providers/group.rb @@ -41,7 +41,7 @@ class TestGroupProvider < Test::Unit::TestCase } assert(group, "Could not create provider group") - return group + group end case Facter["operatingsystem"].value @@ -63,7 +63,7 @@ class TestGroupProvider < Test::Unit::TestCase end } - return nil + nil end def remove(group) @@ -85,7 +85,7 @@ class TestGroupProvider < Test::Unit::TestCase return obj.gid } - return nil + nil end def remove(group) diff --git a/test/ral/providers/host/parsed.rb b/test/ral/providers/host/parsed.rb index 2060276d7..d14e33f7b 100755 --- a/test/ral/providers/host/parsed.rb +++ b/test/ral/providers/host/parsed.rb @@ -62,7 +62,7 @@ class TestParsedHostProvider < Test::Unit::TestCase host.send(name.to_s + "=", val) end - return host + host end # Make sure we convert both directlys correctly using a simple host. diff --git a/test/ral/providers/mailalias/aliases.rb b/test/ral/providers/mailalias/aliases.rb index 76bbc60c6..8c2626ee9 100755 --- a/test/ral/providers/mailalias/aliases.rb +++ b/test/ral/providers/mailalias/aliases.rb @@ -43,7 +43,7 @@ class TestMailaliasAliasesProvider < Test::Unit::TestCase key.send(p.to_s + "=", v) end - return key + key end def test_data_parsing_and_generating diff --git a/test/ral/providers/package.rb b/test/ral/providers/package.rb index 03b81477d..b91f5d92d 100755 --- a/test/ral/providers/package.rb +++ b/test/ral/providers/package.rb @@ -33,7 +33,7 @@ class TestPackageProvider < Test::Unit::TestCase end } - return array + array end def self.suitable_test_packages diff --git a/test/ral/providers/provider.rb b/test/ral/providers/provider.rb index 081020638..3ffbfd985 100755 --- a/test/ral/providers/provider.rb +++ b/test/ral/providers/provider.rb @@ -13,7 +13,7 @@ class TestProvider < Test::Unit::TestCase raise "Could not find 'echo' binary; cannot complete test" unless echo - return echo + echo end def newprovider @@ -23,7 +23,7 @@ class TestProvider < Test::Unit::TestCase end provider.initvars - return provider + provider end def setup diff --git a/test/ral/providers/sshkey/parsed.rb b/test/ral/providers/sshkey/parsed.rb index e58f59173..2b4d3a603 100755 --- a/test/ral/providers/sshkey/parsed.rb +++ b/test/ral/providers/sshkey/parsed.rb @@ -44,7 +44,7 @@ class TestParsedSSHKey < Test::Unit::TestCase key.send(p.to_s + "=", v) end - return key + key end def test_keysparse diff --git a/test/ral/providers/user.rb b/test/ral/providers/user.rb index 793b6493e..033632894 100755 --- a/test/ral/providers/user.rb +++ b/test/ral/providers/user.rb @@ -57,7 +57,7 @@ class TestUserProvider < Test::Unit::TestCase end } - return nil + nil end def remove(user) @@ -83,7 +83,7 @@ class TestUserProvider < Test::Unit::TestCase return obj.send(user.posixmethod(param)) } - return nil + nil end def remove(user) @@ -146,7 +146,7 @@ class TestUserProvider < Test::Unit::TestCase } assert(user, "Could not create provider user") - return user + user end def test_list diff --git a/test/ral/type/cron.rb b/test/ral/type/cron.rb index 37cba1b3c..384a6ad32 100755 --- a/test/ral/type/cron.rb +++ b/test/ral/type/cron.rb @@ -76,7 +76,7 @@ class TestCron < Test::Unit::TestCase cron = @crontype.new(args) } - return cron + cron end # Run the cron through its paces -- install it then remove it. diff --git a/test/ral/type/file.rb b/test/ral/type/file.rb index f7c4c2b2a..726dcb72f 100755 --- a/test/ral/type/file.rb +++ b/test/ral/type/file.rb @@ -16,7 +16,7 @@ class TestFile < Test::Unit::TestCase assert_nothing_raised { file = Puppet::Type.type(:file).new(hash) } - return file + file end def mktestfile diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb index 7541a7cbe..d3eb537c1 100755 --- a/test/ral/type/filesources.rb +++ b/test/ral/type/filesources.rb @@ -93,7 +93,7 @@ class TestFileSources < Test::Unit::TestCase source = "puppet://localhost/#{networked}#{fromdir}" if networked recursive_source_test(source, todir) - return [fromdir,todir, File.join(todir, "one"), File.join(todir, "two")] + [fromdir,todir, File.join(todir, "one"), File.join(todir, "two")] end def test_complex_sources_twice @@ -226,7 +226,7 @@ class TestFileSources < Test::Unit::TestCase } @@tmpfiles << file - return file + file end def test_unmountedNetworkSources diff --git a/test/ral/type/host.rb b/test/ral/type/host.rb index 3259e3ae9..2715f6438 100755 --- a/test/ral/type/host.rb +++ b/test/ral/type/host.rb @@ -54,7 +54,7 @@ class TestHost < Test::Unit::TestCase ) } - return host + host end def test_list diff --git a/test/ral/type/sshkey.rb b/test/ral/type/sshkey.rb index 01d72156a..4e5525bd3 100755 --- a/test/ral/type/sshkey.rb +++ b/test/ral/type/sshkey.rb @@ -59,7 +59,7 @@ class TestSSHKey < Test::Unit::TestCase @catalog.add_resource(key) - return key + key end def test_instances diff --git a/test/ral/type/user.rb b/test/ral/type/user.rb index 3187101e1..fd5dcd199 100755 --- a/test/ral/type/user.rb +++ b/test/ral/type/user.rb @@ -78,7 +78,7 @@ class TestUser < Test::Unit::TestCase assert(user, "Did not create user") - return user + user end def test_autorequire diff --git a/test/ral/type/yumrepo.rb b/test/ral/type/yumrepo.rb index fcfd73f99..8efa83518 100755 --- a/test/ral/type/yumrepo.rb +++ b/test/ral/type/yumrepo.rb @@ -89,7 +89,7 @@ class TestYumRepo < Test::Unit::TestCase def all_sections(inifile) sections = [] inifile.each_section { |section| sections << section.name } - return sections.sort + sections.sort end def copy_datafiles diff --git a/test/ral/type/zone.rb b/test/ral/type/zone.rb index c136fbfb1..f6ef98a6e 100755 --- a/test/ral/type/zone.rb +++ b/test/ral/type/zone.rb @@ -33,7 +33,7 @@ class TestZone < PuppetTest::TestCase @@zones << name - return zone + zone end def test_instances |
