Please review pull request #401: Revert #12101 opened by (pcarlisle)

Description:

This doesn't work on rspec < 2.6.0 and is more work than it's worth to fix right this second.

  • Opened: Tue Jan 24 22:12:33 UTC 2012
  • Based on: puppetlabs:2.7.x (586074aca8dd49843ebfb9f160b408b7907cf886)
  • Requested merge: pcarlisle:backout-12101 (8ec0b6c86cb081b4d82b9badf51e3cf8acdca4b8)

Diff follows:

diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index d870465..5203fb0 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -196,7 +196,7 @@ def absolute_path?(path, platform=nil)
       :posix   => %r!^/!,
     }
     require 'puppet'
-    platform ||= File::ALT_SEPARATOR ? :windows : :posix
+    platform ||= Puppet.features.microsoft_windows? ? :windows : :posix
 
     !! (path =~ regexes[platform])
   end
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index 8051d01..2e8710a 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -48,7 +48,7 @@ def self.loaded(file)
 
   def initialize(obj, path, options = {})
     @path = path.to_s
-    raise ArgumentError, "Autoload paths cannot be fully qualified" if absolute_path?(@path)
+    raise ArgumentError, "Autoload paths cannot be fully qualified" if @path !~ /^\w/
     @object = obj
 
     self.class[obj] = self
diff --git a/spec/shared_behaviours/path_parameters.rb b/spec/shared_behaviours/path_parameters.rb
index 2d195a1..bdcd4cf 100755
--- a/spec/shared_behaviours/path_parameters.rb
+++ b/spec/shared_behaviours/path_parameters.rb
@@ -87,7 +87,26 @@ def instance(path)
     @param = param
   end
 
-  describe "on a Unix-like platform it", :as_platform => :posix do
+  before :each do
+    @file_separator = File::SEPARATOR
+  end
+  after :each do
+    with_verbose_disabled do
+      verbose, $VERBOSE = $VERBOSE, nil
+      File::SEPARATOR = @file_separator
+      $VERBOSE = verbose
+    end
+  end
+
+  describe "on a Unix-like platform it" do
+    before :each do
+      with_verbose_disabled do
+        File::SEPARATOR = '/'
+      end
+      Puppet.features.stubs(:microsoft_windows?).returns(false)
+      Puppet.features.stubs(:posix?).returns(true)
+    end
+
     if array then
       it_should_behave_like "all pathname parameters with arrays", false
     end
@@ -115,7 +134,15 @@ def instance(path)
     end
   end
 
-  describe "on a Windows-like platform it", :as_platform => :windows do
+  describe "on a Windows-like platform it" do
+    before :each do
+      with_verbose_disabled do
+        File::SEPARATOR = '\\'
+      end
+      Puppet.features.stubs(:microsoft_windows?).returns(true)
+      Puppet.features.stubs(:posix?).returns(false)
+    end
+
     if array then
       it_should_behave_like "all pathname parameters with arrays", true
     end
diff --git a/spec/shared_contexts/platform.rb b/spec/shared_contexts/platform.rb
deleted file mode 100644
index bb5a36e..0000000
--- a/spec/shared_contexts/platform.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# Contexts for stubbing platforms
-
-shared_context "windows", :as_platform => :windows do
-  before :each do
-    Facter.stubs(:value).with(:operatingsystem).returns 'Windows'
-    Puppet.features.stubs(:microsoft_windows?).returns(true)
-    Puppet.features.stubs(:posix?).returns(false)
-  end
-
-  around do |example|
-    file_alt_separator = File::ALT_SEPARATOR
-    with_verbose_disabled do
-      File::ALT_SEPARATOR = '\\'
-    end
-    example.run
-    with_verbose_disabled do
-      File::ALT_SEPARATOR = file_alt_separator
-    end
-  end
-end
-
-shared_context "posix", :as_platform => :posix do
-  before :each do
-    Puppet.features.stubs(:microsoft_windows?).returns(false)
-    Puppet.features.stubs(:posix?).returns(true)
-  end
-
-  around do |example|
-    file_alt_separator = File::ALT_SEPARATOR
-    with_verbose_disabled do
-      File::ALT_SEPARATOR = nil
-    end
-    example.run
-    with_verbose_disabled do
-      File::ALT_SEPARATOR = file_alt_separator
-    end
-  end
-end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index fd208e9..e0227be 100755
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -24,10 +24,6 @@ module PuppetSpec
 require 'monkey_patches/alias_should_to_must'
 require 'monkey_patches/publicize_methods'
 
-Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|
-  require file.relative_path_from(Pathname.new(dir))
-end
-
 Pathname.glob("#{dir}/shared_behaviours/**/*.rb") do |behaviour|
   require behaviour.relative_path_from(Pathname.new(dir))
 end
diff --git a/spec/unit/parser/functions/generate_spec.rb b/spec/unit/parser/functions/generate_spec.rb
index 8b9d851..e508053 100755
--- a/spec/unit/parser/functions/generate_spec.rb
+++ b/spec/unit/parser/functions/generate_spec.rb
@@ -41,7 +41,11 @@
     scope.function_generate([command]).should == 'yay'
   end
 
-  describe "on Windows", :as_platform => :windows do
+  describe "on Windows" do
+    before :each do
+      Puppet.features.stubs(:microsoft_windows?).returns(true)
+    end
+
     it "should accept lower-case drive letters" do
       command = 'd:/command/foo'
       Dir.expects(:chdir).with(File.dirname(command)).returns("yay")
@@ -69,7 +73,11 @@
     end
   end
 
-  describe "on non-Windows", :as_platform => :posix do
+  describe "on non-Windows" do
+    before :each do
+      Puppet.features.stubs(:microsoft_windows?).returns(false)
+    end
+
     it "should reject backslashes" do
       lambda { scope.function_generate(['/com\\mand']) }.should raise_error(Puppet::ParseError)
     end
diff --git a/spec/unit/provider/exec/windows_spec.rb b/spec/unit/provider/exec/windows_spec.rb
index 5e1b5c9..748646a 100755
--- a/spec/unit/provider/exec/windows_spec.rb
+++ b/spec/unit/provider/exec/windows_spec.rb
@@ -2,12 +2,18 @@
 
 require 'spec_helper'
 
-describe Puppet::Type.type(:exec).provider(:windows), :as_platform => :windows do
+describe Puppet::Type.type(:exec).provider(:windows) do
   include PuppetSpec::Files
 
   let(:resource) { Puppet::Type.type(:exec).new(:title => 'C:\foo', :provider => :windows) }
   let(:provider) { described_class.new(resource) }
 
+  before :each do
+    Facter.stubs(:value).with(:operatingsystem).returns 'Windows'
+    Puppet.features.stubs(:microsoft_windows?).returns(true)
+    Puppet.features.stubs(:posix?).returns(false)
+  end
+
   after :all do
     # This provider may not be suitable on some machines, so we want to reset
     # the default so it isn't used by mistake in future specs.
diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb
index 3bb607b..5a4c392 100755
--- a/spec/unit/type/exec_spec.rb
+++ b/spec/unit/type/exec_spec.rb
@@ -187,7 +187,12 @@ def exec_tester(command, exitstatus = 0, rest = {})
   end
 
   describe "when setting user" do
-    describe "on POSIX systems", :as_platform => :posix do
+    describe "on POSIX systems" do
+      before :each do
+        Puppet.features.stubs(:posix?).returns(true)
+        Puppet.features.stubs(:microsoft_windows?).returns(false)
+      end
+
       it "should fail if we are not root" do
         Puppet.features.stubs(:root?).returns(false)
         expect { Puppet::Type.type(:exec).new(:name => '/bin/true whatever', :user => 'input') }.
@@ -203,8 +208,10 @@ def exec_tester(command, exitstatus = 0, rest = {})
       end
     end
 
-    describe "on Windows systems", :as_platform => :windows do
+    describe "on Windows systems" do
       before :each do
+        Puppet.features.stubs(:posix?).returns(false)
+        Puppet.features.stubs(:microsoft_windows?).returns(true)
         Puppet.features.stubs(:root?).returns(true)
       end
 
@@ -482,13 +489,13 @@ def test(command, valid)
         end
       end
     end
-  end
 
-  describe "when setting creates" do
-    it_should_behave_like "all path parameters", :creates, :array => true do
-      def instance(path)
-        # Specify shell provider so we don't have to care about command validation
-        Puppet::Type.type(:exec).new(:name => @executable, :creates => path, :provider => :shell)
+    describe "when setting creates" do
+      it_should_behave_like "all path parameters", :creates, :array => true do
+        def instance(path)
+          # Specify shell provider so we don't have to care about command validation
+          Puppet::Type.type(:exec).new(:name => @executable, :creates => path, :provider => :shell)
+        end
       end
     end
   end
diff --git a/spec/unit/util/log/destinations_spec.rb b/spec/unit/util/log/destinations_spec.rb
index da6494e..3cb8e24 100755
--- a/spec/unit/util/log/destinations_spec.rb
+++ b/spec/unit/util/log/destinations_spec.rb
@@ -44,14 +44,18 @@
       end
     end
 
-    describe "on POSIX systems", :as_platform => :posix do
+    describe "on POSIX systems" do
+      before :each do Puppet.features.stubs(:microsoft_windows?).returns false end
+
       let (:abspath) { '/tmp/log' }
       let (:relpath) { 'log' }
 
       it_behaves_like "file destination"
     end
 
-    describe "on Windows systems", :as_platform => :windows do
+    describe "on Windows systems" do
+      before :each do Puppet.features.stubs(:microsoft_windows?).returns true end
+
       let (:abspath) { 'C:\\temp\\log.txt' }
       let (:relpath) { 'log.txt' }
 
diff --git a/spec/unit/util_spec.rb b/spec/unit/util_spec.rb
index 77dc313..35358d6 100755
--- a/spec/unit/util_spec.rb
+++ b/spec/unit/util_spec.rb
@@ -12,18 +12,18 @@ def process_status(exitstatus)
   end
 
   describe "#absolute_path?" do
-    describe "on posix systems", :as_platform => :posix do
-      it "should default to the platform of the local system" do
-        Puppet::Util.should be_absolute_path('/foo')
-        Puppet::Util.should_not be_absolute_path('C:/foo')
-      end
-    end
+    it "should default to the platform of the local system" do
+      Puppet.features.stubs(:posix?).returns(true)
+      Puppet.features.stubs(:microsoft_windows?).returns(false)
 
-    describe "on windows", :as_platform => :windows do
-      it "should default to the platform of the local system" do
-        Puppet::Util.should be_absolute_path('C:/foo')
-        Puppet::Util.should_not be_absolute_path('/foo')
-      end
+      Puppet::Util.should be_absolute_path('/foo')
+      Puppet::Util.should_not be_absolute_path('C:/foo')
+
+      Puppet.features.stubs(:posix?).returns(false)
+      Puppet.features.stubs(:microsoft_windows?).returns(true)
+
+      Puppet::Util.should be_absolute_path('C:/foo')
+      Puppet::Util.should_not be_absolute_path('/foo')
     end
 
     describe "when using platform :posix" do

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to