<feed xmlns='http://www.w3.org/2005/Atom'>
<title>puppet.git/test/puppet, branch ticket/master/8119</title>
<subtitle>Puppet repo</subtitle>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/'/>
<entry>
<title>Merge branch '2.6.x' into 2.7.x</title>
<updated>2011-08-17T18:41:26+00:00</updated>
<author>
<name>Jacob Helwig</name>
<email>jacob@puppetlabs.com</email>
</author>
<published>2011-08-17T18:41:26+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=3a3a5100305a5334397c350f4e8e42a7f9b7e3f6'/>
<id>3a3a5100305a5334397c350f4e8e42a7f9b7e3f6</id>
<content type='text'>
* 2.6.x:
  Reset indirector state after configurer tests.
  (#8770) Don't fail to set supplementary groups when changing user to root
  (#8770) Always fully drop privileges when changing user
  (#8662) Migrate suidmanager test case to rspec
  (#8740) Do not enumerate files in the root directory.
  (#3553) Explain that cron resources require time attributes

Conflicts:
	lib/puppet/application/resource.rb
	test/puppet/tc_suidmanager.rb
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* 2.6.x:
  Reset indirector state after configurer tests.
  (#8770) Don't fail to set supplementary groups when changing user to root
  (#8770) Always fully drop privileges when changing user
  (#8662) Migrate suidmanager test case to rspec
  (#8740) Do not enumerate files in the root directory.
  (#3553) Explain that cron resources require time attributes

Conflicts:
	lib/puppet/application/resource.rb
	test/puppet/tc_suidmanager.rb
</pre>
</div>
</content>
</entry>
<entry>
<title>(#8662) Migrate suidmanager test case to rspec</title>
<updated>2011-08-12T00:05:07+00:00</updated>
<author>
<name>Nick Lewis</name>
<email>nick@puppetlabs.com</email>
</author>
<published>2011-08-11T22:47:37+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=00c4b25010068eeb57a15104fb178a72af733fda'/>
<id>00c4b25010068eeb57a15104fb178a72af733fda</id>
<content type='text'>
We're trying to move away from the legacy Test::Unit tests, and toward rspec
specs, so rewrite this file as specs.

Reviewed-By: Jacob Helwig &lt;jacob@puppetlabs.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We're trying to move away from the legacy Test::Unit tests, and toward rspec
specs, so rewrite this file as specs.

Reviewed-By: Jacob Helwig &lt;jacob@puppetlabs.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>maint: Use expand_path when requiring spec_helper or puppettest</title>
<updated>2010-12-06T20:01:18+00:00</updated>
<author>
<name>Matt Robinson</name>
<email>matt@puppetlabs.com</email>
</author>
<published>2010-12-06T20:01:18+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=626d7564467bdc0e9d2d385e9aa10c539d9ed175'/>
<id>626d7564467bdc0e9d2d385e9aa10c539d9ed175</id>
<content type='text'>
Doing a require to a relative path can cause files to be required more
than once when they're required from different relative paths.  If you
expand the path fully, this won't happen.  Ruby 1.9 also requires that
you use expand_path when doing these requires.

Paired-with: Jesse Wolfe
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Doing a require to a relative path can cause files to be required more
than once when they're required from different relative paths.  If you
expand the path fully, this won't happen.  Ruby 1.9 also requires that
you use expand_path when doing these requires.

Paired-with: Jesse Wolfe
</pre>
</div>
</content>
</entry>
<entry>
<title>Maint. fix for test broken by 00eedac5</title>
<updated>2010-11-11T04:56:42+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-11-11T04:56:42+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=cc5224c1912f2e95663c14ca803700070130fb69'/>
<id>cc5224c1912f2e95663c14ca803700070130fb69</id>
<content type='text'>
As per Nigel, this fixes the test broken by commit 00eedac5 in which a :combine
was added in lib but the corresponding change was not made in the test.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
As per Nigel, this fixes the test broken by commit 00eedac5 in which a :combine
was added in lib but the corresponding change was not made in the test.
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Two space indentation</title>
<updated>2010-07-10T01:12:17+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:12:17+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=3180b9d9b2c844dade1d361326600f7001ec66dd'/>
<id>3180b9d9b2c844dade1d361326600f7001ec66dd</id>
<content type='text'>
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 =&gt; "foo", :desc =&gt; "anything", :settings =&gt; 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 =&gt; "foo", :desc =&gt; "anything", :settings =&gt; 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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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 =&gt; "foo", :desc =&gt; "anything", :settings =&gt; 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 =&gt; "foo", :desc =&gt; "anything", :settings =&gt; 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
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Line modifiers are preferred to one-line blocks.</title>
<updated>2010-07-10T01:06:06+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:06:06+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=81e283b28cdd91d259e3b60687aee7ea66e9d05d'/>
<id>81e283b28cdd91d259e3b60687aee7ea66e9d05d</id>
<content type='text'>
* Replaced 6 occurances of (while .*?) *do$ with

  The do is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          while line = f.gets do
      becomes:
          while line = f.gets
      The code:
          while line = shadow.gets do
      becomes:
          while line = shadow.gets
      The code:
          while wrapper = zeros.pop do
      becomes:
          while wrapper = zeros.pop

* Replaced 19 occurances of ((if|unless) .*?) *then$ with

  The then is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
      becomes:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
      The code:
          unless defined?(@spec_command) then
      becomes:
          unless defined?(@spec_command)
      The code:
          if c == ?\n then
      becomes:
          if c == ?\n

* Replaced 758 occurances of

      ((?:if|unless|while|until) .*)
          (.*)
      end

  with

  The one-line form is preferable provided:

      * The condition is not used to assign a variable
      * The body line is not already modified
      * The resulting line is not too long

  3 Examples:

      The code:
          if Puppet.features.libshadow?
              has_feature :manages_passwords
          end
      becomes:
          has_feature :manages_passwords if Puppet.features.libshadow?
      The code:
          unless (defined?(@current_pool) and @current_pool)
              @current_pool = process_zpool_data(get_pool_data)
          end
      becomes:
          @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
      The code:
          if Puppet[:trace]
              puts detail.backtrace
          end
      becomes:
          puts detail.backtrace if Puppet[:trace]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 6 occurances of (while .*?) *do$ with

  The do is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          while line = f.gets do
      becomes:
          while line = f.gets
      The code:
          while line = shadow.gets do
      becomes:
          while line = shadow.gets
      The code:
          while wrapper = zeros.pop do
      becomes:
          while wrapper = zeros.pop

* Replaced 19 occurances of ((if|unless) .*?) *then$ with

  The then is unneeded in the block header form and causes problems
  with the block-to-one-line transformation.

  3 Examples:

      The code:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
      becomes:
          if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
      The code:
          unless defined?(@spec_command) then
      becomes:
          unless defined?(@spec_command)
      The code:
          if c == ?\n then
      becomes:
          if c == ?\n

* Replaced 758 occurances of

      ((?:if|unless|while|until) .*)
          (.*)
      end

  with

  The one-line form is preferable provided:

      * The condition is not used to assign a variable
      * The body line is not already modified
      * The resulting line is not too long

  3 Examples:

      The code:
          if Puppet.features.libshadow?
              has_feature :manages_passwords
          end
      becomes:
          has_feature :manages_passwords if Puppet.features.libshadow?
      The code:
          unless (defined?(@current_pool) and @current_pool)
              @current_pool = process_zpool_data(get_pool_data)
          end
      becomes:
          @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
      The code:
          if Puppet[:trace]
              puts detail.backtrace
          end
      becomes:
          puts detail.backtrace if Puppet[:trace]
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Use string interpolation</title>
<updated>2010-07-10T01:05:55+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:05:55+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=e8cf06336b64491a2dd7538a06651e0caaf6a48d'/>
<id>e8cf06336b64491a2dd7538a06651e0caaf6a48d</id>
<content type='text'>
* Replaced 83 occurances of

      (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[])

  with

      \1#{\2}"

  3 Examples:

      The code:
          puts "PUPPET " + status + ": " + process + ", " + state
      becomes:
          puts "PUPPET " + status + ": " + process + ", #{state}"
      The code:
          puts "PUPPET " + status + ": #{process}" + ", #{state}"
      becomes:
          puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
      The code:
          }.compact.join( "\n" ) + "\n" + t + "]\n"
      becomes:
          }.compact.join( "\n" ) + "\n#{t}" + "]\n"

* Replaced 21 occurances of (.*)" *[+] *" with \1

  3 Examples:

      The code:
          puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
      becomes:
          puts "PUPPET #{status}" + ": #{process}, #{state}"
      The code:
          puts "PUPPET #{status}" + ": #{process}, #{state}"
      becomes:
          puts "PUPPET #{status}: #{process}, #{state}"
      The code:
          res = self.class.name + ": #{@name}" + "\n"
      becomes:
          res = self.class.name + ": #{@name}\n"

* Don't use string concatenation to split lines unless they would be very long.

  Replaced 11 occurances of

      (.*)(['"]) *[+]
       *(['"])(.*)

  with

  3 Examples:

      The code:
          o.define_head "The check_puppet Nagios plug-in checks that specified " +
              "Puppet process is running and the state file is no " +
      becomes:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
      The code:
          o.separator   "Mandatory arguments to long options are mandatory for " +
          "short options too."
      becomes:
          o.separator   "Mandatory arguments to long options are mandatory for short options too."
      The code:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
              "older than specified interval."
      becomes:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval."

* Replaced no occurances of do (.*?) end with {\1}

* Replaced 1488 occurances of

      "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b)

  with

  20 Examples:

      The code:
          args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",")
      becomes:
          args[0].split(/\./).map do |s| "dc=#{s}" end.join(",")
      The code:
          puts "%s" % Puppet.version
      becomes:
          puts "#{Puppet.version}"
      The code:
          raise "Could not find information for %s" % node
      becomes:
          raise "Could not find information for #{node}"
      The code:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
      becomes:
          raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file"
      The code:
          Puppet.err "Could not run %s: %s" % [client_class, detail]
      becomes:
          Puppet.err "Could not run #{client_class}: #{detail}"
      The code:
          raise "Could not find handler for %s" % arg
      becomes:
          raise "Could not find handler for #{arg}"
      The code:
          Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
      becomes:
          Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
      The code:
          raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail
      becomes:
          raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
      The code:
          raise "Could not find facts for %s" % Puppet[:certname]
      becomes:
          raise "Could not find facts for #{Puppet[:certname]}"
      The code:
          raise ArgumentError, "%s is not readable" % path
      becomes:
          raise ArgumentError, "#{path} is not readable"
      The code:
          raise ArgumentError, "Invalid handler %s" % name
      becomes:
          raise ArgumentError, "Invalid handler #{name}"
      The code:
          debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str]
      becomes:
          debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'"
      The code:
          raise Puppet::Error, "unknown cert type '%s'" % hash[:type]
      becomes:
          raise Puppet::Error, "unknown cert type '#{hash[:type]}'"
      The code:
          Puppet.info "Creating a new certificate request for %s" % Puppet[:certname]
      becomes:
          Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
      The code:
          "Cannot create alias %s: object already exists" % [name]
      becomes:
          "Cannot create alias #{name}: object already exists"
      The code:
          return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum]
      becomes:
          return "replacing from source #{metadata.source} with contents #{metadata.checksum}"
      The code:
          it "should have a %s parameter" % param do
      becomes:
          it "should have a #{param} parameter" do
      The code:
          describe "when registring '%s' messages" % log do
      becomes:
          describe "when registring '#{log}' messages" do
      The code:
          paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l }
      becomes:
          paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" }
      The code:
          assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do
      becomes:
          assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 83 occurances of

      (.*)" *[+] *([$@]?[\w_0-9.:]+?)(.to_s\b)?(?! *[*(%\w_0-9.:{\[])

  with

      \1#{\2}"

  3 Examples:

      The code:
          puts "PUPPET " + status + ": " + process + ", " + state
      becomes:
          puts "PUPPET " + status + ": " + process + ", #{state}"
      The code:
          puts "PUPPET " + status + ": #{process}" + ", #{state}"
      becomes:
          puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
      The code:
          }.compact.join( "\n" ) + "\n" + t + "]\n"
      becomes:
          }.compact.join( "\n" ) + "\n#{t}" + "]\n"

* Replaced 21 occurances of (.*)" *[+] *" with \1

  3 Examples:

      The code:
          puts "PUPPET #{status}" + ": #{process}" + ", #{state}"
      becomes:
          puts "PUPPET #{status}" + ": #{process}, #{state}"
      The code:
          puts "PUPPET #{status}" + ": #{process}, #{state}"
      becomes:
          puts "PUPPET #{status}: #{process}, #{state}"
      The code:
          res = self.class.name + ": #{@name}" + "\n"
      becomes:
          res = self.class.name + ": #{@name}\n"

* Don't use string concatenation to split lines unless they would be very long.

  Replaced 11 occurances of

      (.*)(['"]) *[+]
       *(['"])(.*)

  with

  3 Examples:

      The code:
          o.define_head "The check_puppet Nagios plug-in checks that specified " +
              "Puppet process is running and the state file is no " +
      becomes:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
      The code:
          o.separator   "Mandatory arguments to long options are mandatory for " +
          "short options too."
      becomes:
          o.separator   "Mandatory arguments to long options are mandatory for short options too."
      The code:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no " +
              "older than specified interval."
      becomes:
          o.define_head "The check_puppet Nagios plug-in checks that specified Puppet process is running and the state file is no older than specified interval."

* Replaced no occurances of do (.*?) end with {\1}

* Replaced 1488 occurances of

      "([^"\n]*%s[^"\n]*)" *% *(.+?)(?=$| *\b(do|if|while|until|unless|#)\b)

  with

  20 Examples:

      The code:
          args[0].split(/\./).map do |s| "dc=%s"%[s] end.join(",")
      becomes:
          args[0].split(/\./).map do |s| "dc=#{s}" end.join(",")
      The code:
          puts "%s" % Puppet.version
      becomes:
          puts "#{Puppet.version}"
      The code:
          raise "Could not find information for %s" % node
      becomes:
          raise "Could not find information for #{node}"
      The code:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
      becomes:
          raise Puppet::Error, "Cannot create #{dir}: basedir #{File.join(path)} is a file"
      The code:
          Puppet.err "Could not run %s: %s" % [client_class, detail]
      becomes:
          Puppet.err "Could not run #{client_class}: #{detail}"
      The code:
          raise "Could not find handler for %s" % arg
      becomes:
          raise "Could not find handler for #{arg}"
      The code:
          Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
      becomes:
          Puppet.err "Will not start without authorization file #{Puppet[:authconfig]}"
      The code:
          raise Puppet::Error, "Could not deserialize catalog from pson: %s" % detail
      becomes:
          raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
      The code:
          raise "Could not find facts for %s" % Puppet[:certname]
      becomes:
          raise "Could not find facts for #{Puppet[:certname]}"
      The code:
          raise ArgumentError, "%s is not readable" % path
      becomes:
          raise ArgumentError, "#{path} is not readable"
      The code:
          raise ArgumentError, "Invalid handler %s" % name
      becomes:
          raise ArgumentError, "Invalid handler #{name}"
      The code:
          debug "Executing '%s' in zone %s with '%s'" % [command, @resource[:name], str]
      becomes:
          debug "Executing '#{command}' in zone #{@resource[:name]} with '#{str}'"
      The code:
          raise Puppet::Error, "unknown cert type '%s'" % hash[:type]
      becomes:
          raise Puppet::Error, "unknown cert type '#{hash[:type]}'"
      The code:
          Puppet.info "Creating a new certificate request for %s" % Puppet[:certname]
      becomes:
          Puppet.info "Creating a new certificate request for #{Puppet[:certname]}"
      The code:
          "Cannot create alias %s: object already exists" % [name]
      becomes:
          "Cannot create alias #{name}: object already exists"
      The code:
          return "replacing from source %s with contents %s" % [metadata.source, metadata.checksum]
      becomes:
          return "replacing from source #{metadata.source} with contents #{metadata.checksum}"
      The code:
          it "should have a %s parameter" % param do
      becomes:
          it "should have a #{param} parameter" do
      The code:
          describe "when registring '%s' messages" % log do
      becomes:
          describe "when registring '#{log}' messages" do
      The code:
          paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration%stest" % l }
      becomes:
          paths = %w{a b c d e f g h}.collect { |l| "/tmp/iteration#{l}test" }
      The code:
          assert_raise(Puppet::Error, "Check '%s' did not fail on false" % check) do
      becomes:
          assert_raise(Puppet::Error, "Check '#{check}' did not fail on false") do
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: English names for special globals rather than line-noise</title>
<updated>2010-07-10T01:05:08+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:05:08+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=eefccf252527dc5b69af5959b0b0e2ddb5c91b74'/>
<id>eefccf252527dc5b69af5959b0b0e2ddb5c91b74</id>
<content type='text'>
* 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 [$]&amp; with $MATCH

  3 Examples:

      The code:
          work.slice!(0, $&amp;.length)
      becomes:
          work.slice!(0, $MATCH.length)
      The code:
          if $&amp;
      becomes:
          if $MATCH
      The code:
          if $&amp;
      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")
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* 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 [$]&amp; with $MATCH

  3 Examples:

      The code:
          work.slice!(0, $&amp;.length)
      becomes:
          work.slice!(0, $MATCH.length)
      The code:
          if $&amp;
      becomes:
          if $MATCH
      The code:
          if $&amp;
      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")
</pre>
</div>
</content>
</entry>
<entry>
<title>Code smell: Inconsistent indentation and related formatting issues</title>
<updated>2010-07-10T01:05:04+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-07-10T01:05:04+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=9ee56f2e67be973da49b1d3f21de1bf87de35e6f'/>
<id>9ee56f2e67be973da49b1d3f21de1bf87de35e6f</id>
<content type='text'>
* Replaced 163 occurances of

      defined\? +([@a-zA-Z_.0-9?=]+)

  with

      defined?(\1)

  This makes detecting subsequent patterns easier.

  3 Examples:

      The code:
          if ! defined? @parse_config
      becomes:
          if ! defined?(@parse_config)
      The code:
          return @option_parser if defined? @option_parser
      becomes:
          return @option_parser if defined?(@option_parser)
      The code:
          if defined? @local and @local
      becomes:
          if defined?(@local) and @local

* Eliminate trailing spaces.

  Replaced 428 occurances of ^(.*?) +$ with \1

  1 file was skipped.

      test/ral/providers/host/parsed.rb because 0

* Replace leading tabs with an appropriate number of spaces.

  Replaced 306 occurances of ^(\t+)(.*) with

  Tabs are not consistently expanded in all environments.

* Don't arbitrarily wrap on sprintf (%) operator.

  Replaced 143 occurances of

      (.*['"] *%)
       +(.*)

  with

  Splitting the line does nothing to aid clarity and hinders further refactorings.

  3 Examples:

      The code:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" %
              [dir, File.join(path)]
      becomes:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
      The code:
          Puppet.err "Will not start without authorization file %s" %
              Puppet[:authconfig]
      becomes:
          Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
      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, $?.exitstatus]

* Don't break short arrays/parameter list in two.

  Replaced 228 occurances of

      (.*)
       +(.*)

  with

  3 Examples:

      The code:
          puts @format.wrap(type.provider(prov).doc,
                            :indent =&gt; 4, :scrub =&gt; true)
      becomes:
          puts @format.wrap(type.provider(prov).doc, :indent =&gt; 4, :scrub =&gt; true)
      The code:
          assert(FileTest.exists?(daily),
              "Did not make daily graph for %s" % type)
      becomes:
          assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type)
      The code:
          assert(prov.target_object(:first).read !~ /^notdisk/,
              "Did not remove thing from disk")
      becomes:
          assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk")

* If arguments must wrap, treat them all equally

  Replaced 510 occurances of

      lines ending in things like ...(foo, or ...(bar(1,3),

  with

      \1
          \2

  3 Examples:

      The code:
          midscope.to_hash(false),
      becomes:
          assert_equal(
      The code:
          botscope.to_hash(true),
      becomes:
          # bottomscope, then checking that we see the right stuff.
      The code:
          :path =&gt; link,
      becomes:

* Replaced 4516 occurances of ^( *)(.*) with

  The present code base is supposed to use four-space indentation.  In some places we failed
  to maintain that standard.  These should be fixed regardless of the 2 vs. 4 space question.

  15 Examples:

      The code:

          def run_comp(cmd)
             puts cmd
             results = []
             old_sync = $stdout.sync
             $stdout.sync = true
             line = []
             begin
                open("| #{cmd}", "r") do |f|
                  until f.eof? do
                    c = f.getc
      becomes:

          def run_comp(cmd)
              puts cmd
              results = []
              old_sync = $stdout.sync
              $stdout.sync = true
              line = []
              begin
                  open("| #{cmd}", "r") do |f|
                      until f.eof? do
                          c = f.getc
      The code:
                              s.gsub!(/.{4}/n, '\\\\u\&amp;')
                            }
              string.force_encoding(Encoding::UTF_8)
              string
            rescue Iconv::Failure =&gt; e
              raise GeneratorError, "Caught #{e.class}: #{e}"
            end
          else
            def utf8_to_pson(string) # :nodoc:
              string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&amp;] }
              string.gsub!(/(
      becomes:
                                      s.gsub!(/.{4}/n, '\\\\u\&amp;')
                                  }
                  string.force_encoding(Encoding::UTF_8)
                  string
              rescue Iconv::Failure =&gt; e
                  raise GeneratorError, "Caught #{e.class}: #{e}"
              end
          else
              def utf8_to_pson(string) # :nodoc:
                  string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&amp;] }
                  string.gsub!(/(
      The code:
              end
          }

          rvalues:      rvalue
                      | rvalues comma rvalue {
              if val[0].instance_of?(AST::ASTArray)
                  result = val[0].push(val[2])
              else
                  result = ast AST::ASTArray, :children =&gt; [val[0],val[2]]
              end
          }
      becomes:
              end
          }

          rvalues:      rvalue
              | rvalues comma rvalue {
                  if val[0].instance_of?(AST::ASTArray)
                  result = val[0].push(val[2])
              else
                  result = ast AST::ASTArray, :children =&gt; [val[0],val[2]]
              end
          }
      The code:
          #passwdproc = proc { @password }

                      keytext = @key.export(

              OpenSSL::Cipher::DES.new(:EDE3, :CBC),

              @password
          )
          File.open(@keyfile, "w", 0400) { |f|
              f &lt;&lt; keytext
          }
      becomes:
          #        passwdproc = proc { @password }

              keytext = @key.export(

                  OpenSSL::Cipher::DES.new(:EDE3, :CBC),

                  @password
                  )
                  File.open(@keyfile, "w", 0400) { |f|
                      f &lt;&lt; keytext
                  }
      The code:
          end

          def to_manifest
              "%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
                   @params.collect { |p, v|
                       if v.is_a? Array
                           "    #{p} =&gt; [\'#{v.join("','")}\']"
                       else
                           "    #{p} =&gt; \'#{v}\'"
                       end
                   }.join(",\n")
      becomes:
          end

          def to_manifest
              "%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
                  @params.collect { |p, v|
                      if v.is_a? Array
                          "    #{p} =&gt; [\'#{v.join("','")}\']"
                      else
                          "    #{p} =&gt; \'#{v}\'"
                      end
                  }.join(",\n")
      The code:
          via the augeas tool.

           Requires:
             - augeas to be installed (http://www.augeas.net)
             - ruby-augeas bindings

           Sample usage with a string::

              augeas{\"test1\" :
                     context =&gt; \"/files/etc/sysconfig/firstboot\",
                     changes =&gt; \"set RUN_FIRSTBOOT YES\",
      becomes:
          via the augeas tool.

          Requires:
              - augeas to be installed (http://www.augeas.net)
              - ruby-augeas bindings

          Sample usage with a string::

              augeas{\"test1\" :
                  context =&gt; \"/files/etc/sysconfig/firstboot\",
                  changes =&gt; \"set RUN_FIRSTBOOT YES\",
      The code:
              names.should_not be_include("root")
          end

          describe "when generating a purgeable resource" do
              it "should be included in the generated resources" do
                  Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
                  @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
              end
          end

          describe "when the instance's do not have an ensure property" do
      becomes:
              names.should_not be_include("root")
          end

          describe "when generating a purgeable resource" do
              it "should be included in the generated resources" do
                  Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
                  @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
              end
          end

          describe "when the instance's do not have an ensure property" do
      The code:
          describe "when the instance's do not have an ensure property" do
              it "should not be included in the generated resources" do
                  @no_ensure_resource = Puppet::Type.type(:exec).new(:name =&gt; '/usr/bin/env echo')
                  Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
                  @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
              end
          end

          describe "when the instance's ensure property does not accept absent" do
              it "should not be included in the generated resources" do
                  @no_absent_resource = Puppet::Type.type(:service).new(:name =&gt; 'foobar')
      becomes:
          describe "when the instance's do not have an ensure property" do
              it "should not be included in the generated resources" do
                  @no_ensure_resource = Puppet::Type.type(:exec).new(:name =&gt; '/usr/bin/env echo')
                  Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
                  @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
              end
          end

          describe "when the instance's ensure property does not accept absent" do
              it "should not be included in the generated resources" do
                  @no_absent_resource = Puppet::Type.type(:service).new(:name =&gt; 'foobar')
      The code:
          func = nil
          assert_nothing_raised do

                          func = Puppet::Parser::AST::Function.new(

                  :name =&gt; "template",
                  :ftype =&gt; :rvalue,

                  :arguments =&gt; AST::ASTArray.new(
                      :children =&gt; [stringobj(template)]
                  )
      becomes:
          func = nil
          assert_nothing_raised do

              func = Puppet::Parser::AST::Function.new(

                  :name =&gt; "template",
                  :ftype =&gt; :rvalue,

                  :arguments =&gt; AST::ASTArray.new(
                      :children =&gt; [stringobj(template)]
                  )
      The code:

                  assert(
              @store.allowed?("hostname.madstop.com", "192.168.1.50"),

          "hostname not allowed")

                  assert(
              ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),

          "subname name allowed")
      becomes:

          assert(
              @store.allowed?("hostname.madstop.com", "192.168.1.50"),

          "hostname not allowed")

              assert(
                  ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),

          "subname name allowed")
      The code:

          assert_nothing_raised {

                          server = Puppet::Network::Handler.fileserver.new(

                  :Local =&gt; true,

                  :Config =&gt; false
              )
          }

      becomes:

          assert_nothing_raised {

              server = Puppet::Network::Handler.fileserver.new(

                  :Local =&gt; true,

                  :Config =&gt; false
              )
          }

      The code:
               'yay',
                                               { :failonfail =&gt; false,
                                                 :uid =&gt; @user.uid,

                                                 :gid =&gt; @user.gid }
                                             ).returns('output')

          output = Puppet::Util::SUIDManager.run_and_capture 'yay',
                                                             @user.uid,
                                                             @user.gid
      becomes:
                  'yay',
                      { :failonfail =&gt; false,
                          :uid =&gt; @user.uid,

                          :gid =&gt; @user.gid }
                              ).returns('output')

          output = Puppet::Util::SUIDManager.run_and_capture 'yay',
              @user.uid,
              @user.gid
      The code:
                      ).times(1)
          pkg.provider.expects(
                          :aptget

                                  ).with(

                          '-y',
                          '-q',
                          'remove',

                          'faff'
      becomes:
                      ).times(1)
          pkg.provider.expects(
              :aptget

                  ).with(

                      '-y',
                      '-q',
                      'remove',

                      'faff'
      The code:
          johnny one two
          billy three four\n"

                  # Just parse and generate, to make sure it's isomorphic.
                  assert_nothing_raised do
                      assert_equal(text, @parser.to_file(@parser.parse(text)),
                          "parsing was not isomorphic")
                  end
              end

              def test_valid_attrs
      becomes:
          johnny one two
          billy three four\n"

          #         Just parse and generate, to make sure it's isomorphic.
          assert_nothing_raised do
              assert_equal(text, @parser.to_file(@parser.parse(text)),
                  "parsing was not isomorphic")
                  end
              end

              def test_valid_attrs
      The code:
                  "testing",
                              :onboolean =&gt; [true, "An on bool"],

                              :string =&gt; ["a string", "A string arg"]
                              )
          result = []
          should = []
          assert_nothing_raised("Add args failed") do
              @config.addargs(result)
          end
          @config.each do |name, element|
      becomes:
                  "testing",
                      :onboolean =&gt; [true, "An on bool"],

                      :string =&gt; ["a string", "A string arg"]
                      )
          result = []
          should = []
          assert_nothing_raised("Add args failed") do
              @config.addargs(result)
          end
          @config.each do |name, element|
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
* Replaced 163 occurances of

      defined\? +([@a-zA-Z_.0-9?=]+)

  with

      defined?(\1)

  This makes detecting subsequent patterns easier.

  3 Examples:

      The code:
          if ! defined? @parse_config
      becomes:
          if ! defined?(@parse_config)
      The code:
          return @option_parser if defined? @option_parser
      becomes:
          return @option_parser if defined?(@option_parser)
      The code:
          if defined? @local and @local
      becomes:
          if defined?(@local) and @local

* Eliminate trailing spaces.

  Replaced 428 occurances of ^(.*?) +$ with \1

  1 file was skipped.

      test/ral/providers/host/parsed.rb because 0

* Replace leading tabs with an appropriate number of spaces.

  Replaced 306 occurances of ^(\t+)(.*) with

  Tabs are not consistently expanded in all environments.

* Don't arbitrarily wrap on sprintf (%) operator.

  Replaced 143 occurances of

      (.*['"] *%)
       +(.*)

  with

  Splitting the line does nothing to aid clarity and hinders further refactorings.

  3 Examples:

      The code:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" %
              [dir, File.join(path)]
      becomes:
          raise Puppet::Error, "Cannot create %s: basedir %s is a file" % [dir, File.join(path)]
      The code:
          Puppet.err "Will not start without authorization file %s" %
              Puppet[:authconfig]
      becomes:
          Puppet.err "Will not start without authorization file %s" % Puppet[:authconfig]
      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, $?.exitstatus]

* Don't break short arrays/parameter list in two.

  Replaced 228 occurances of

      (.*)
       +(.*)

  with

  3 Examples:

      The code:
          puts @format.wrap(type.provider(prov).doc,
                            :indent =&gt; 4, :scrub =&gt; true)
      becomes:
          puts @format.wrap(type.provider(prov).doc, :indent =&gt; 4, :scrub =&gt; true)
      The code:
          assert(FileTest.exists?(daily),
              "Did not make daily graph for %s" % type)
      becomes:
          assert(FileTest.exists?(daily), "Did not make daily graph for %s" % type)
      The code:
          assert(prov.target_object(:first).read !~ /^notdisk/,
              "Did not remove thing from disk")
      becomes:
          assert(prov.target_object(:first).read !~ /^notdisk/, "Did not remove thing from disk")

* If arguments must wrap, treat them all equally

  Replaced 510 occurances of

      lines ending in things like ...(foo, or ...(bar(1,3),

  with

      \1
          \2

  3 Examples:

      The code:
          midscope.to_hash(false),
      becomes:
          assert_equal(
      The code:
          botscope.to_hash(true),
      becomes:
          # bottomscope, then checking that we see the right stuff.
      The code:
          :path =&gt; link,
      becomes:

* Replaced 4516 occurances of ^( *)(.*) with

  The present code base is supposed to use four-space indentation.  In some places we failed
  to maintain that standard.  These should be fixed regardless of the 2 vs. 4 space question.

  15 Examples:

      The code:

          def run_comp(cmd)
             puts cmd
             results = []
             old_sync = $stdout.sync
             $stdout.sync = true
             line = []
             begin
                open("| #{cmd}", "r") do |f|
                  until f.eof? do
                    c = f.getc
      becomes:

          def run_comp(cmd)
              puts cmd
              results = []
              old_sync = $stdout.sync
              $stdout.sync = true
              line = []
              begin
                  open("| #{cmd}", "r") do |f|
                      until f.eof? do
                          c = f.getc
      The code:
                              s.gsub!(/.{4}/n, '\\\\u\&amp;')
                            }
              string.force_encoding(Encoding::UTF_8)
              string
            rescue Iconv::Failure =&gt; e
              raise GeneratorError, "Caught #{e.class}: #{e}"
            end
          else
            def utf8_to_pson(string) # :nodoc:
              string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&amp;] }
              string.gsub!(/(
      becomes:
                                      s.gsub!(/.{4}/n, '\\\\u\&amp;')
                                  }
                  string.force_encoding(Encoding::UTF_8)
                  string
              rescue Iconv::Failure =&gt; e
                  raise GeneratorError, "Caught #{e.class}: #{e}"
              end
          else
              def utf8_to_pson(string) # :nodoc:
                  string = string.gsub(/["\\\x0-\x1f]/) { MAP[$&amp;] }
                  string.gsub!(/(
      The code:
              end
          }

          rvalues:      rvalue
                      | rvalues comma rvalue {
              if val[0].instance_of?(AST::ASTArray)
                  result = val[0].push(val[2])
              else
                  result = ast AST::ASTArray, :children =&gt; [val[0],val[2]]
              end
          }
      becomes:
              end
          }

          rvalues:      rvalue
              | rvalues comma rvalue {
                  if val[0].instance_of?(AST::ASTArray)
                  result = val[0].push(val[2])
              else
                  result = ast AST::ASTArray, :children =&gt; [val[0],val[2]]
              end
          }
      The code:
          #passwdproc = proc { @password }

                      keytext = @key.export(

              OpenSSL::Cipher::DES.new(:EDE3, :CBC),

              @password
          )
          File.open(@keyfile, "w", 0400) { |f|
              f &lt;&lt; keytext
          }
      becomes:
          #        passwdproc = proc { @password }

              keytext = @key.export(

                  OpenSSL::Cipher::DES.new(:EDE3, :CBC),

                  @password
                  )
                  File.open(@keyfile, "w", 0400) { |f|
                      f &lt;&lt; keytext
                  }
      The code:
          end

          def to_manifest
              "%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
                   @params.collect { |p, v|
                       if v.is_a? Array
                           "    #{p} =&gt; [\'#{v.join("','")}\']"
                       else
                           "    #{p} =&gt; \'#{v}\'"
                       end
                   }.join(",\n")
      becomes:
          end

          def to_manifest
              "%s { '%s':\n%s\n}" % [self.type.to_s, self.name,
                  @params.collect { |p, v|
                      if v.is_a? Array
                          "    #{p} =&gt; [\'#{v.join("','")}\']"
                      else
                          "    #{p} =&gt; \'#{v}\'"
                      end
                  }.join(",\n")
      The code:
          via the augeas tool.

           Requires:
             - augeas to be installed (http://www.augeas.net)
             - ruby-augeas bindings

           Sample usage with a string::

              augeas{\"test1\" :
                     context =&gt; \"/files/etc/sysconfig/firstboot\",
                     changes =&gt; \"set RUN_FIRSTBOOT YES\",
      becomes:
          via the augeas tool.

          Requires:
              - augeas to be installed (http://www.augeas.net)
              - ruby-augeas bindings

          Sample usage with a string::

              augeas{\"test1\" :
                  context =&gt; \"/files/etc/sysconfig/firstboot\",
                  changes =&gt; \"set RUN_FIRSTBOOT YES\",
      The code:
              names.should_not be_include("root")
          end

          describe "when generating a purgeable resource" do
              it "should be included in the generated resources" do
                  Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
                  @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
              end
          end

          describe "when the instance's do not have an ensure property" do
      becomes:
              names.should_not be_include("root")
          end

          describe "when generating a purgeable resource" do
              it "should be included in the generated resources" do
                  Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
                  @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
              end
          end

          describe "when the instance's do not have an ensure property" do
      The code:
          describe "when the instance's do not have an ensure property" do
              it "should not be included in the generated resources" do
                  @no_ensure_resource = Puppet::Type.type(:exec).new(:name =&gt; '/usr/bin/env echo')
                  Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
                  @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
              end
          end

          describe "when the instance's ensure property does not accept absent" do
              it "should not be included in the generated resources" do
                  @no_absent_resource = Puppet::Type.type(:service).new(:name =&gt; 'foobar')
      becomes:
          describe "when the instance's do not have an ensure property" do
              it "should not be included in the generated resources" do
                  @no_ensure_resource = Puppet::Type.type(:exec).new(:name =&gt; '/usr/bin/env echo')
                  Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
                  @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
              end
          end

          describe "when the instance's ensure property does not accept absent" do
              it "should not be included in the generated resources" do
                  @no_absent_resource = Puppet::Type.type(:service).new(:name =&gt; 'foobar')
      The code:
          func = nil
          assert_nothing_raised do

                          func = Puppet::Parser::AST::Function.new(

                  :name =&gt; "template",
                  :ftype =&gt; :rvalue,

                  :arguments =&gt; AST::ASTArray.new(
                      :children =&gt; [stringobj(template)]
                  )
      becomes:
          func = nil
          assert_nothing_raised do

              func = Puppet::Parser::AST::Function.new(

                  :name =&gt; "template",
                  :ftype =&gt; :rvalue,

                  :arguments =&gt; AST::ASTArray.new(
                      :children =&gt; [stringobj(template)]
                  )
      The code:

                  assert(
              @store.allowed?("hostname.madstop.com", "192.168.1.50"),

          "hostname not allowed")

                  assert(
              ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),

          "subname name allowed")
      becomes:

          assert(
              @store.allowed?("hostname.madstop.com", "192.168.1.50"),

          "hostname not allowed")

              assert(
                  ! @store.allowed?("name.sub.madstop.com", "192.168.0.50"),

          "subname name allowed")
      The code:

          assert_nothing_raised {

                          server = Puppet::Network::Handler.fileserver.new(

                  :Local =&gt; true,

                  :Config =&gt; false
              )
          }

      becomes:

          assert_nothing_raised {

              server = Puppet::Network::Handler.fileserver.new(

                  :Local =&gt; true,

                  :Config =&gt; false
              )
          }

      The code:
               'yay',
                                               { :failonfail =&gt; false,
                                                 :uid =&gt; @user.uid,

                                                 :gid =&gt; @user.gid }
                                             ).returns('output')

          output = Puppet::Util::SUIDManager.run_and_capture 'yay',
                                                             @user.uid,
                                                             @user.gid
      becomes:
                  'yay',
                      { :failonfail =&gt; false,
                          :uid =&gt; @user.uid,

                          :gid =&gt; @user.gid }
                              ).returns('output')

          output = Puppet::Util::SUIDManager.run_and_capture 'yay',
              @user.uid,
              @user.gid
      The code:
                      ).times(1)
          pkg.provider.expects(
                          :aptget

                                  ).with(

                          '-y',
                          '-q',
                          'remove',

                          'faff'
      becomes:
                      ).times(1)
          pkg.provider.expects(
              :aptget

                  ).with(

                      '-y',
                      '-q',
                      'remove',

                      'faff'
      The code:
          johnny one two
          billy three four\n"

                  # Just parse and generate, to make sure it's isomorphic.
                  assert_nothing_raised do
                      assert_equal(text, @parser.to_file(@parser.parse(text)),
                          "parsing was not isomorphic")
                  end
              end

              def test_valid_attrs
      becomes:
          johnny one two
          billy three four\n"

          #         Just parse and generate, to make sure it's isomorphic.
          assert_nothing_raised do
              assert_equal(text, @parser.to_file(@parser.parse(text)),
                  "parsing was not isomorphic")
                  end
              end

              def test_valid_attrs
      The code:
                  "testing",
                              :onboolean =&gt; [true, "An on bool"],

                              :string =&gt; ["a string", "A string arg"]
                              )
          result = []
          should = []
          assert_nothing_raised("Add args failed") do
              @config.addargs(result)
          end
          @config.each do |name, element|
      becomes:
                  "testing",
                      :onboolean =&gt; [true, "An on bool"],

                      :string =&gt; ["a string", "A string arg"]
                      )
          result = []
          should = []
          assert_nothing_raised("Add args failed") do
              @config.addargs(result)
          end
          @config.each do |name, element|
</pre>
</div>
</content>
</entry>
<entry>
<title>Use the 'root' feature rather than directly checking the uid</title>
<updated>2010-02-17T14:50:53+00:00</updated>
<author>
<name>Markus Roberts</name>
<email>Markus@reality.com</email>
</author>
<published>2010-06-10T00:47:39+00:00</published>
<link rel='alternate' type='text/html' href='https://fedorapeople.org/cgit/ricky/public_git/puppet.git/commit/?id=2396ebac9021eaa4a2983e60902c04cc9e0db0ee'/>
<id>2396ebac9021eaa4a2983e60902c04cc9e0db0ee</id>
<content type='text'>
Jesse fixed all these but David and others moved them and introduced some more so...
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Jesse fixed all these but David and others moved them and introduced some more so...
</pre>
</div>
</content>
</entry>
</feed>
