diff options
| author | TP Honey <tphoney@users.noreply.github.com> | 2015-05-06 13:55:22 +0100 | 
|---|---|---|
| committer | TP Honey <tphoney@users.noreply.github.com> | 2015-05-06 13:55:22 +0100 | 
| commit | 4f6c6fa3e5ebb26589f4504470ad30ea9304977f (patch) | |
| tree | 21d0171d3ff1b81467f8a9b1f78d37150d142c62 | |
| parent | cf251303be2e89619e0b99f01fb90ed5e676dfa2 (diff) | |
| parent | f49eb6b8e20a8517916d984d1606daaabbba9a23 (diff) | |
| download | puppet-stdlib-4f6c6fa3e5ebb26589f4504470ad30ea9304977f.tar.gz puppet-stdlib-4f6c6fa3e5ebb26589f4504470ad30ea9304977f.tar.bz2  | |
Merge pull request #448 from DavidS/fix_range
range(): fix TypeError(can't convert nil into Integer) when using range ...
| -rw-r--r-- | lib/puppet/parser/functions/range.rb | 6 | ||||
| -rwxr-xr-x | spec/functions/range_spec.rb | 7 | 
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index c14f6e6..2fc2113 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -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 diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index ef86f97..f18b89e 100755 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -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  | 
