diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:48 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:48 -0700 |
| commit | 42a539061293f8e745a9dc5b97b4415b6a275e04 (patch) | |
| tree | fb268244b7ca95dd36e8136bcd3c02fd2a05632f /test | |
| parent | a07bbe2e711ee22a40e147c046997c8813ae3cc8 (diff) | |
| download | puppet-42a539061293f8e745a9dc5b97b4415b6a275e04.tar.gz puppet-42a539061293f8e745a9dc5b97b4415b6a275e04.tar.xz puppet-42a539061293f8e745a9dc5b97b4415b6a275e04.zip | |
Code smell: Use ||= for conditional initialization
Replaced 55 occurances of
([$@]?\w+) += +(.*) +(if +\1.nil\?|if +! *\1|unless +\1|unless +defined\?\(\1\))$
with
\1 ||= \2
3 Examples:
The code:
@sync
becomes:
@sync
The code:
becomes:
The code:
if @yydebug
becomes:
if @yydebug
Diffstat (limited to 'test')
| -rw-r--r-- | test/lib/puppettest/filetesting.rb | 4 | ||||
| -rwxr-xr-x | test/ral/providers/cron/crontab.rb | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/test/lib/puppettest/filetesting.rb b/test/lib/puppettest/filetesting.rb index 6f07c2ad4..79981ce9c 100644 --- a/test/lib/puppettest/filetesting.rb +++ b/test/lib/puppettest/filetesting.rb @@ -32,9 +32,9 @@ module PuppetTest::FileTesting def mkranddirsandfiles(dirs = nil,files = nil,depth = 3) return if depth < 0 - dirs = %w{This Is A Set Of Directories} unless dirs + dirs ||= %w{This Is A Set Of Directories} - files = %w{and this is a set of files} unless files + files ||= %w{and this is a set of files} tfiles = randlist(files) tdirs = randlist(dirs) diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb index 3dfac96e6..41d12c8db 100755 --- a/test/ral/providers/cron/crontab.rb +++ b/test/ral/providers/cron/crontab.rb @@ -23,7 +23,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # a full cron job. These tests assume individual record types will always be correctly # parsed, so all they def sample_crons - @sample_crons = YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml"))) unless defined?(@sample_crons) + @sample_crons ||= YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml"))) @sample_crons end @@ -31,7 +31,7 @@ class TestCronParsedProvider < Test::Unit::TestCase # mapping between records and lines. We have plenty of redundancy here because # we use these records to build up our complex, multi-line cron jobs below. def sample_records - @sample_records = YAML.load(File.read(File.join(@crondir, "crontab_sample_records.yaml"))) unless defined?(@sample_records) + @sample_records ||= YAML.load(File.read(File.join(@crondir, "crontab_sample_records.yaml"))) @sample_records end |
