[Pkg-puppet-devel] [facter] 138/352: (FACT-134) Redo tests so the work on ruby 1.8.x

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:39 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 1de2d8d7ad823e744d5861440c87cd675170549b
Author: Josh Cooper <josh at puppetlabs.com>
Date:   Thu Jan 9 17:20:20 2014 -0800

    (FACT-134) Redo tests so the work on ruby 1.8.x
    
    No String#encode or Encoding in ruby 1.8.x, update tests accordingly.
---
 spec/unit/util/normalization_spec.rb | 12 ++++++++++--
 spec/unit/util/resolution_spec.rb    | 24 ++++++++++++++++++++----
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/spec/unit/util/normalization_spec.rb b/spec/unit/util/normalization_spec.rb
index 34f9d10..51c3ef1 100644
--- a/spec/unit/util/normalization_spec.rb
+++ b/spec/unit/util/normalization_spec.rb
@@ -8,11 +8,19 @@ describe Facter::Util::Normalization do
   subject { described_class }
 
   def utf16(str)
-    str.encode(Encoding::UTF_16LE)
+    if String.method_defined?(:encode) && defined?(::Encoding)
+      str.encode(Encoding::UTF_16LE)
+    else
+      str
+    end
   end
 
   def utf8(str)
-    str.encode(Encoding::UTF_8)
+    if String.method_defined?(:encode) && defined?(::Encoding)
+      str.encode(Encoding::UTF_8)
+    else
+      str
+    end
   end
 
   describe "validating strings" do
diff --git a/spec/unit/util/resolution_spec.rb b/spec/unit/util/resolution_spec.rb
index 755b252..78bc151 100755
--- a/spec/unit/util/resolution_spec.rb
+++ b/spec/unit/util/resolution_spec.rb
@@ -181,7 +181,23 @@ describe Facter::Util::Resolution do
   end
 
   describe "when returning the value" do
-    let(:utf16_string) { "".encode(Encoding::UTF_16LE).freeze }
+    let(:fact_value) { "" }
+
+    let(:utf16_string) do
+      if String.method_defined?(:encode) && defined?(::Encoding)
+        fact_value.encode(Encoding::UTF_16LE).freeze
+      else
+        [0x00, 0x00].pack('C*').freeze
+      end
+    end
+
+    let(:expected_value) do
+      if String.method_defined?(:encode) && defined?(::Encoding)
+        fact_value.encode(Encoding::UTF_8).freeze
+      else
+        [0x00, 0x00].pack('C*').freeze
+      end
+    end
 
     before do
       @resolve = Facter::Util::Resolution.new("yay")
@@ -217,7 +233,7 @@ describe Facter::Util::Resolution do
 
           Facter::Util::Resolution.expects(:exec).once.returns(utf16_string)
 
-          expect(@resolve.value).to eq(utf16_string.encode(Encoding::UTF_8))
+          expect(@resolve.value).to eq(expected_value)
         end
       end
 
@@ -238,7 +254,7 @@ describe Facter::Util::Resolution do
 
           Facter::Util::Resolution.expects(:exec).once.returns(utf16_string)
 
-          expect(@resolve.value).to eq(utf16_string.encode(Encoding::UTF_8))
+          expect(@resolve.value).to eq(expected_value)
         end
       end
     end
@@ -258,7 +274,7 @@ describe Facter::Util::Resolution do
       it "it normalizes the resolved value" do
         @resolve.setcode { utf16_string }
 
-        expect(@resolve.value).to eq(utf16_string.encode(Encoding::UTF_8))
+        expect(@resolve.value).to eq(expected_value)
       end
 
       it "should use its limit method to determine the timeout, to avoid conflict when a 'timeout' method exists for some other reason" do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list