[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Daniel Pittman daniel at puppetlabs.com
Tue May 10 08:11:08 UTC 2011


The following commit has been merged in the experimental branch:
commit a125536350880ef886de843b8106e2422eabe0d5
Author: Daniel Pittman <daniel at puppetlabs.com>
Date:   Wed Apr 6 11:08:40 2011 -0700

    (#6995) more robust testing of string loading
    
    We were flushing loaded string versions in the test suite, but were not
    clearing out the $" array used to determine if we had previously loaded that
    file.
    
    This lead to situations where tests cross-polluted because require though the
    code was in memory, but the effects of loading that code had all been rolled
    back.
    
    Reviewed-By: Dan Bode <dan at puppetlabs.com>

diff --git a/spec/unit/string/string_collection_spec.rb b/spec/unit/string/string_collection_spec.rb
index 184299e..fa63f18 100755
--- a/spec/unit/string/string_collection_spec.rb
+++ b/spec/unit/string/string_collection_spec.rb
@@ -4,18 +4,22 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
 require 'tmpdir'
 
 describe Puppet::String::StringCollection do
-  before :all do
-    @strings = subject.instance_variable_get("@strings")
-    @strings_backup = @strings.dup
+  # To avoid cross-pollution we have to save and restore both the hash
+  # containing all the string data, and the array used by require.  Restoring
+  # both means that we don't leak side-effects across the code. --daniel 2011-04-06
+  before :each do
+    @original_strings  = subject.instance_variable_get("@strings").dup
+    @original_required = $".dup
+    subject.instance_variable_get("@strings").clear
   end
 
-  before { @strings.clear }
-
-  after :all do
-    subject.instance_variable_set("@strings", @strings_backup)
+  after :each do
+    subject.instance_variable_set("@strings", @original_strings)
+    $".clear ; @original_required.each do |item| $" << item end
   end
 
   describe "::strings" do
+    it "REVISIT: should have some tests here, if we describe it"
   end
 
   describe "::validate_version" do
@@ -88,7 +92,7 @@ describe Puppet::String::StringCollection do
 
     it "should attempt to require the string if it is not registered" do
       subject.expects(:require).with do |file|
-        @strings[:bar]['0.0.1'] = true
+        subject.instance_variable_get("@strings")[:bar]['0.0.1'] = true
         file == 'puppet/string/bar'
       end
       subject.string?("bar", '0.0.1').should == true
@@ -104,7 +108,7 @@ describe Puppet::String::StringCollection do
       subject.expects(:require).with('puppet/string/bar').
         raises(LoadError, 'no such file to load -- puppet/string/bar')
       subject.expects(:require).with do |file|
-        @strings[:bar]['0.0.1'] = true
+        subject.instance_variable_get("@strings")[:bar]['0.0.1'] = true
         file == 'bar at 0.0.1/puppet/string/bar'
       end
       subject.string?("bar", '0.0.1').should == true
@@ -124,31 +128,31 @@ describe Puppet::String::StringCollection do
 
     it "should register the version loaded by `:current` as `:current`" do
       subject.expects(:require).with do |file|
-        @strings[:huzzah]['2.0.1'] = :huzzah_string
+        subject.instance_variable_get("@strings")[:huzzah]['2.0.1'] = :huzzah_string
         file == 'puppet/string/huzzah'
       end
       subject.string?("huzzah", :current)
-      @strings[:huzzah][:current].should == :huzzah_string
+      subject.instance_variable_get("@strings")[:huzzah][:current].should == :huzzah_string
     end
 
     it "should register the version loaded from `puppet/string/{name}` as `:current`" do
       subject.expects(:require).with do |file|
-        @strings[:huzzah]['2.0.1'] = :huzzah_string
+        subject.instance_variable_get("@strings")[:huzzah]['2.0.1'] = :huzzah_string
         file == 'puppet/string/huzzah'
       end
       subject.string?("huzzah", '2.0.1')
-      @strings[:huzzah][:current].should == :huzzah_string
+      subject.instance_variable_get("@strings")[:huzzah][:current].should == :huzzah_string
     end
 
     it "should not register the version loaded from `{name}@{version}` as `:current`" do
       subject.expects(:require).with('puppet/string/huzzah').
         raises(LoadError, 'no such file to load -- puppet/string/huzzah')
       subject.expects(:require).with do |file|
-        @strings[:huzzah]['0.0.1'] = true
+        subject.instance_variable_get("@strings")[:huzzah]['0.0.1'] = true
         file == 'huzzah at 0.0.1/puppet/string/huzzah'
       end
       subject.string?("huzzah", '0.0.1')
-      @strings[:huzzah].should_not have_key(:current)
+      subject.instance_variable_get("@strings")[:huzzah].should_not have_key(:current)
     end
   end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list