|
4 | 4 | describe "the range function" do
|
5 | 5 | let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
6 | 6 |
|
7 |
| - it "should exist" do |
| 7 | + it "exists" do |
8 | 8 | Puppet::Parser::Functions.function("range").should == "function_range"
|
9 | 9 | end
|
10 | 10 |
|
11 |
| - it "should raise a ParseError if there is less than 1 arguments" do |
12 |
| - lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError)) |
| 11 | + it "raises a ParseError if there is less than 1 arguments" do |
| 12 | + expect { scope.function_range([]) }.to raise_error Puppet::ParseError, /Wrong number of arguments.*0 for 1/ |
13 | 13 | end
|
14 | 14 |
|
15 |
| - it "should return a letter range" do |
16 |
| - result = scope.function_range(["a","d"]) |
17 |
| - result.should(eq(['a','b','c','d'])) |
18 |
| - end |
| 15 | + describe 'with a letter range' do |
| 16 | + it "returns a letter range" do |
| 17 | + result = scope.function_range(["a","d"]) |
| 18 | + result.should eq ['a','b','c','d'] |
| 19 | + end |
| 20 | + |
| 21 | + it "returns a letter range given a step of 1" do |
| 22 | + result = scope.function_range(["a","d","1"]) |
| 23 | + result.should eq ['a','b','c','d'] |
| 24 | + end |
19 | 25 |
|
20 |
| - it "should return a number range" do |
21 |
| - result = scope.function_range(["1","4"]) |
22 |
| - result.should(eq([1,2,3,4])) |
| 26 | + it "returns a stepped letter range" do |
| 27 | + result = scope.function_range(["a","d","2"]) |
| 28 | + result.should eq ['a','c'] |
| 29 | + end |
| 30 | + |
| 31 | + it "returns a stepped letter range given a negative step" do |
| 32 | + result = scope.function_range(["a","d","-2"]) |
| 33 | + result.should eq ['a','c'] |
| 34 | + end |
23 | 35 | end
|
24 | 36 |
|
25 |
| - it "should work with padded hostname like strings" do |
26 |
| - expected = ("host01".."host10").to_a |
27 |
| - scope.function_range(["host01","host10"]).should eq expected |
| 37 | + describe 'with a number range' do |
| 38 | + it "returns a number range" do |
| 39 | + result = scope.function_range(["1","4"]) |
| 40 | + result.should eq [1,2,3,4] |
| 41 | + end |
| 42 | + |
| 43 | + it "returns a number range given a step of 1" do |
| 44 | + result = scope.function_range(["1","4","1"]) |
| 45 | + result.should eq [1,2,3,4] |
| 46 | + end |
| 47 | + |
| 48 | + it "returns a stepped number range" do |
| 49 | + result = scope.function_range(["1","4","2"]) |
| 50 | + result.should eq [1,3] |
| 51 | + end |
| 52 | + |
| 53 | + it "returns a stepped number range given a negative step" do |
| 54 | + result = scope.function_range(["1","4","-2"]) |
| 55 | + result.should eq [1,3] |
| 56 | + end |
28 | 57 | end
|
29 | 58 |
|
30 |
| - it "should coerce zero padded digits to integers" do |
31 |
| - expected = (0..10).to_a |
32 |
| - scope.function_range(["00", "10"]).should eq expected |
| 59 | + describe 'with a numeric-like string range' do |
| 60 | + it "works with padded hostname like strings" do |
| 61 | + expected = ("host01".."host10").to_a |
| 62 | + scope.function_range(["host01","host10"]).should eq expected |
| 63 | + end |
| 64 | + |
| 65 | + it "coerces zero padded digits to integers" do |
| 66 | + expected = (0..10).to_a |
| 67 | + scope.function_range(["00", "10"]).should eq expected |
| 68 | + end |
33 | 69 | end
|
34 | 70 | end
|
0 commit comments