]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
range(): fix TypeError(can't convert nil into Integer) when using range syntax
authorDavid Schmitt <david.schmitt@puppetlabs.com>
Wed, 6 May 2015 09:13:27 +0000 (10:13 +0100)
committerDavid Schmitt <david.schmitt@puppetlabs.com>
Wed, 6 May 2015 09:13:27 +0000 (10:13 +0100)
lib/puppet/parser/functions/range.rb
spec/functions/range_spec.rb

index c14f6e696b88e7ed359e2d84cf8557b8c7479f60..2fc211329d7ffeb619654d9437c1211b2b7c56a3 100644 (file)
@@ -47,7 +47,7 @@ Will return: [0,2,4,6,8]
 
       type = '..' # Use the simplest type of Range available in Ruby
 
-    else # arguments.size == 0
+    else # arguments.size == 1
       value = arguments[0]
 
       if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/)
@@ -55,7 +55,7 @@ Will return: [0,2,4,6,8]
         stop  = m[3]
 
         type = m[2]
-
+        step = 1
       elsif value.match(/^.+$/)
         raise(Puppet::ParseError, "range(): Unable to compute range " +
           "from the value: #{value}")
@@ -78,7 +78,7 @@ Will return: [0,2,4,6,8]
       when '...'         then (start ... stop) # Exclusive of last element
     end
 
-    result = range.step(step).collect { |i| i }
+    result = range.step(step).to_a
 
     return result
   end
index ef86f97199e728443d89dd36d38b7ab1ea192786..f18b89e1a10c916de4543c59c0271151b52d9d14 100755 (executable)
@@ -68,6 +68,13 @@ describe "the range function" do
     end
   end
 
+  describe 'with a ruby-like range' do
+    it "returns a number range" do
+      result = scope.function_range(["1..4"])
+      expect(result).to eq [1,2,3,4]
+    end
+  end
+
   describe 'with a numeric range' do
     it "returns a range of numbers" do
       expected = (1..10).to_a