diff options
author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
---|---|---|
committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:05:08 -0700 |
commit | eefccf252527dc5b69af5959b0b0e2ddb5c91b74 (patch) | |
tree | a37e13c9cd4aab7e8671004cf4f83000b52c96a8 /spec/unit | |
parent | 184132e07fc1461555cb4da842df15f32842a843 (diff) | |
download | puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.gz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.tar.xz puppet-eefccf252527dc5b69af5959b0b0e2ddb5c91b74.zip |
Code smell: English names for special globals rather than line-noise
* Replaced 36 occurances of [$][?] with $CHILD_STATUS
3 Examples:
The code:
print "%s finished with exit code %s\n" % [host, $?.exitstatus]
becomes:
print "%s finished with exit code %s\n" % [host, $CHILD_STATUS.exitstatus]
The code:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $?.exitstatus]
becomes:
$stderr.puts "Could not find host for PID %s with status %s" % [pid, $CHILD_STATUS.exitstatus]
The code:
unless $? == 0
becomes:
unless $CHILD_STATUS == 0
* Replaced 3 occurances of [$][$] with $PID
3 Examples:
The code:
Process.kill(:HUP, $$) if restart_requested?
becomes:
Process.kill(:HUP, $PID) if restart_requested?
The code:
if pid == $$
becomes:
if pid == $PID
The code:
host[:name] = "!invalid.hostname.$$$"
becomes:
host[:name] = "!invalid.hostname.$PID$"
* Replaced 7 occurances of [$]& with $MATCH
3 Examples:
The code:
work.slice!(0, $&.length)
becomes:
work.slice!(0, $MATCH.length)
The code:
if $&
becomes:
if $MATCH
The code:
if $&
becomes:
if $MATCH
* Replaced 28 occurances of [$]:(?!:) with $LOAD_PATH
3 Examples:
The code:
sitelibdir = $:.find { |x| x =~ /site_ruby/ }
becomes:
sitelibdir = $LOAD_PATH.find { |x| x =~ /site_ruby/ }
The code:
$:.unshift "lib"
becomes:
$LOAD_PATH.unshift "lib"
The code:
$:.shift
becomes:
$LOAD_PATH.shift
* Replaced 3 occurances of [$]! with $ERROR_INFO
3 Examples:
The code:
$LOG.fatal("Problem reading #{filepath}: #{$!}")
becomes:
$LOG.fatal("Problem reading #{filepath}: #{$ERROR_INFO}")
The code:
$stderr.puts "Couldn't build man pages: " + $!
becomes:
$stderr.puts "Couldn't build man pages: " + $ERROR_INFO
The code:
$stderr.puts $!.message
becomes:
$stderr.puts $ERROR_INFO.message
* Replaced 3 occurances of ^(.*)[$]" with \1$LOADED_FEATURES
3 Examples:
The code:
unless $".index 'racc/parser.rb'
becomes:
unless $LOADED_FEATURES.index 'racc/parser.rb'
The code:
$".push 'racc/parser.rb'
becomes:
$LOADED_FEATURES.push 'racc/parser.rb'
The code:
$".should be_include("tmp/myfile.rb")
becomes:
$LOADED_FEATURES.should be_include("tmp/myfile.rb")
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/provider/service/debian_spec.rb | 6 | ||||
-rwxr-xr-x | spec/unit/provider/service/init_spec.rb | 6 | ||||
-rwxr-xr-x | spec/unit/provider/service/redhat_spec.rb | 4 | ||||
-rwxr-xr-x | spec/unit/util/autoload_spec.rb | 4 |
4 files changed, 10 insertions, 10 deletions
diff --git a/spec/unit/provider/service/debian_spec.rb b/spec/unit/provider/service/debian_spec.rb index 08cf50c27..1d30eb821 100755 --- a/spec/unit/provider/service/debian_spec.rb +++ b/spec/unit/provider/service/debian_spec.rb @@ -66,13 +66,13 @@ describe provider_class do it "should return true when invoke-rc.d exits with 104 status" do @provider.stubs(:system) - $?.stubs(:exitstatus).returns(104) + $CHILD_STATUS.stubs(:exitstatus).returns(104) @provider.enabled?.should == :true end it "should return true when invoke-rc.d exits with 106 status" do @provider.stubs(:system) - $?.stubs(:exitstatus).returns(106) + $CHILD_STATUS.stubs(:exitstatus).returns(106) @provider.enabled?.should == :true end @@ -80,7 +80,7 @@ describe provider_class do [-100, -1, 0, 1, 100, "foo", "", :true, :false].each do |exitstatus| it "should return false when invoke-rc.d exits with #{exitstatus} status" do @provider.stubs(:system) - $?.stubs(:exitstatus).returns(exitstatus) + $CHILD_STATUS.stubs(:exitstatus).returns(exitstatus) @provider.enabled?.should == :false end end diff --git a/spec/unit/provider/service/init_spec.rb b/spec/unit/provider/service/init_spec.rb index a685cc0d0..b8c279473 100755 --- a/spec/unit/provider/service/init_spec.rb +++ b/spec/unit/provider/service/init_spec.rb @@ -132,13 +132,13 @@ describe provider_class do end it "should consider the process running if the command returns 0" do @provider.expects(:texecute).with(:status, ['/service/path/myservice', :status], false).returns("") - $?.stubs(:exitstatus).returns(0) + $CHILD_STATUS.stubs(:exitstatus).returns(0) @provider.status.should == :running end [-10,-1,1,10].each { |ec| it "should consider the process stopped if the command returns something non-0" do @provider.expects(:texecute).with(:status, ['/service/path/myservice', :status], false).returns("") - $?.stubs(:exitstatus).returns(ec) + $CHILD_STATUS.stubs(:exitstatus).returns(ec) @provider.status.should == :stopped end } @@ -159,7 +159,7 @@ describe provider_class do it "should stop and restart the process" do @provider.expects(:texecute).with(:stop, ['/service/path/myservice', :stop ], true).returns("") @provider.expects(:texecute).with(:start,['/service/path/myservice', :start], true).returns("") - $?.stubs(:exitstatus).returns(0) + $CHILD_STATUS.stubs(:exitstatus).returns(0) @provider.restart end end diff --git a/spec/unit/provider/service/redhat_spec.rb b/spec/unit/provider/service/redhat_spec.rb index 0f919ac84..82596fdcf 100755 --- a/spec/unit/provider/service/redhat_spec.rb +++ b/spec/unit/provider/service/redhat_spec.rb @@ -88,13 +88,13 @@ describe provider_class do end it "should consider the process running if the command returns 0" do @provider.expects(:texecute).with(:status, ['/sbin/service', 'myservice', 'status'], false) - $?.stubs(:exitstatus).returns(0) + $CHILD_STATUS.stubs(:exitstatus).returns(0) @provider.status.should == :running end [-10,-1,1,10].each { |ec| it "should consider the process stopped if the command returns something non-0" do @provider.expects(:texecute).with(:status, ['/sbin/service', 'myservice', 'status'], false) - $?.stubs(:exitstatus).returns(ec) + $CHILD_STATUS.stubs(:exitstatus).returns(ec) @provider.status.should == :stopped end } diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb index 0f73a73d7..4186a1fb7 100755 --- a/spec/unit/util/autoload_spec.rb +++ b/spec/unit/util/autoload_spec.rb @@ -49,7 +49,7 @@ describe Puppet::Util::Autoload do it "should include the module directories, the Puppet libdir, and all of the Ruby load directories" do Puppet.stubs(:[]).with(:libdir).returns(%w{/libdir1 /lib/dir/two /third/lib/dir}.join(File::PATH_SEPARATOR)) @autoload.expects(:module_directories).returns %w{/one /two} - @autoload.search_directories.should == %w{/one /two /libdir1 /lib/dir/two /third/lib/dir} + $: + @autoload.search_directories.should == %w{/one /two /libdir1 /lib/dir/two /third/lib/dir} + $LOAD_PATH end it "should include in its search path all of the search directories that have a subdirectory matching the autoload path" do @@ -91,7 +91,7 @@ describe Puppet::Util::Autoload do @autoload.load("myfile") - $".should be_include("tmp/myfile.rb") + $LOADED_FEATURES.should be_include("tmp/myfile.rb") end end |