Skip to content

Commit 4523bc5

Browse files
committed
Merge branch 'master' into 4.3.x
2 parents 7d4fa05 + ffe21fc commit 4523bc5

94 files changed

Lines changed: 627 additions & 497 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# bool2str.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:bool2str, :type => :rvalue, :doc => <<-EOS
7+
Converts a boolean to a string.
8+
Requires a single boolean as an input.
9+
EOS
10+
) do |arguments|
11+
12+
raise(Puppet::ParseError, "bool2str(): Wrong number of arguments " +
13+
"given (#{arguments.size} for 1)") if arguments.size < 1
14+
15+
value = arguments[0]
16+
klass = value.class
17+
18+
# We can have either true or false, and nothing else
19+
unless [FalseClass, TrueClass].include?(klass)
20+
raise(Puppet::ParseError, 'bool2str(): Requires a boolean to work with')
21+
end
22+
23+
return value.to_s
24+
end
25+
end
26+
27+
# vim: set ts=2 sw=2 et :
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# camelcase.rb
3+
#
4+
5+
module Puppet::Parser::Functions
6+
newfunction(:camelcase, :type => :rvalue, :doc => <<-EOS
7+
Converts the case of a string or all strings in an array to camel case.
8+
EOS
9+
) do |arguments|
10+
11+
raise(Puppet::ParseError, "camelcase(): Wrong number of arguments " +
12+
"given (#{arguments.size} for 1)") if arguments.size < 1
13+
14+
value = arguments[0]
15+
klass = value.class
16+
17+
unless [Array, String].include?(klass)
18+
raise(Puppet::ParseError, 'camelcase(): Requires either ' +
19+
'array or string to work with')
20+
end
21+
22+
if value.is_a?(Array)
23+
# Numbers in Puppet are often string-encoded which is troublesome ...
24+
result = value.collect { |i| i.is_a?(String) ? i.split('_').map{|e| e.capitalize}.join : i }
25+
else
26+
result = value.split('_').map{|e| e.capitalize}.join
27+
end
28+
29+
return result
30+
end
31+
end
32+
33+
# vim: set ts=2 sw=2 et :

spec/functions/abs_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
77

88
it "should exist" do
9-
Puppet::Parser::Functions.function("abs").should == "function_abs"
9+
expect(Puppet::Parser::Functions.function("abs")).to eq("function_abs")
1010
end
1111

1212
it "should raise a ParseError if there is less than 1 arguments" do
13-
lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError))
13+
expect { scope.function_abs([]) }.to( raise_error(Puppet::ParseError))
1414
end
1515

1616
it "should convert a negative number into a positive" do
1717
result = scope.function_abs(["-34"])
18-
result.should(eq(34))
18+
expect(result).to(eq(34))
1919
end
2020

2121
it "should do nothing with a positive number" do
2222
result = scope.function_abs(["5678"])
23-
result.should(eq(5678))
23+
expect(result).to(eq(5678))
2424
end
2525
end

spec/functions/any2array_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,51 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should exist" do
8-
Puppet::Parser::Functions.function("any2array").should == "function_any2array"
8+
expect(Puppet::Parser::Functions.function("any2array")).to eq("function_any2array")
99
end
1010

1111
it "should return an empty array if there is less than 1 argument" do
1212
result = scope.function_any2array([])
13-
result.should(eq([]))
13+
expect(result).to(eq([]))
1414
end
1515

1616
it "should convert boolean true to [ true ] " do
1717
result = scope.function_any2array([true])
18-
result.should(eq([true]))
18+
expect(result).to(eq([true]))
1919
end
2020

2121
it "should convert one object to [object]" do
2222
result = scope.function_any2array(['one'])
23-
result.should(eq(['one']))
23+
expect(result).to(eq(['one']))
2424
end
2525

2626
it "should convert multiple objects to [objects]" do
2727
result = scope.function_any2array(['one', 'two'])
28-
result.should(eq(['one', 'two']))
28+
expect(result).to(eq(['one', 'two']))
2929
end
3030

3131
it "should return empty array it was called with" do
3232
result = scope.function_any2array([[]])
33-
result.should(eq([]))
33+
expect(result).to(eq([]))
3434
end
3535

3636
it "should return one-member array it was called with" do
3737
result = scope.function_any2array([['string']])
38-
result.should(eq(['string']))
38+
expect(result).to(eq(['string']))
3939
end
4040

4141
it "should return multi-member array it was called with" do
4242
result = scope.function_any2array([['one', 'two']])
43-
result.should(eq(['one', 'two']))
43+
expect(result).to(eq(['one', 'two']))
4444
end
4545

4646
it "should return members of a hash it was called with" do
4747
result = scope.function_any2array([{ 'key' => 'value' }])
48-
result.should(eq(['key', 'value']))
48+
expect(result).to(eq(['key', 'value']))
4949
end
5050

5151
it "should return an empty array if it was called with an empty hash" do
5252
result = scope.function_any2array([{ }])
53-
result.should(eq([]))
53+
expect(result).to(eq([]))
5454
end
5555
end

spec/functions/base64_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
77

88
it "should exist" do
9-
Puppet::Parser::Functions.function("base64").should == "function_base64"
9+
expect(Puppet::Parser::Functions.function("base64")).to eq("function_base64")
1010
end
1111

1212
it "should raise a ParseError if there are other than 2 arguments" do
@@ -25,10 +25,10 @@
2525

2626
it "should encode a encoded string" do
2727
result = scope.function_base64(["encode",'thestring'])
28-
result.should =~ /\AdGhlc3RyaW5n\n\Z/
28+
expect(result).to match(/\AdGhlc3RyaW5n\n\Z/)
2929
end
3030
it "should decode a base64 encoded string" do
3131
result = scope.function_base64(["decode",'dGhlc3RyaW5n'])
32-
result.should == 'thestring'
32+
expect(result).to eq('thestring')
3333
end
3434
end

spec/functions/bool2num_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should exist" do
8-
Puppet::Parser::Functions.function("bool2num").should == "function_bool2num"
8+
expect(Puppet::Parser::Functions.function("bool2num")).to eq("function_bool2num")
99
end
1010

1111
it "should raise a ParseError if there is less than 1 arguments" do
12-
lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError))
12+
expect { scope.function_bool2num([]) }.to( raise_error(Puppet::ParseError))
1313
end
1414

1515
it "should convert true to 1" do
1616
result = scope.function_bool2num([true])
17-
result.should(eq(1))
17+
expect(result).to(eq(1))
1818
end
1919

2020
it "should convert false to 0" do
2121
result = scope.function_bool2num([false])
22-
result.should(eq(0))
22+
expect(result).to(eq(0))
2323
end
2424
end

spec/functions/capitalize_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should exist" do
8-
Puppet::Parser::Functions.function("capitalize").should == "function_capitalize"
8+
expect(Puppet::Parser::Functions.function("capitalize")).to eq("function_capitalize")
99
end
1010

1111
it "should raise a ParseError if there is less than 1 arguments" do
12-
lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError))
12+
expect { scope.function_capitalize([]) }.to( raise_error(Puppet::ParseError))
1313
end
1414

1515
it "should capitalize the beginning of a string" do
1616
result = scope.function_capitalize(["abc"])
17-
result.should(eq("Abc"))
17+
expect(result).to(eq("Abc"))
1818
end
1919
end

spec/functions/chomp_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should exist" do
8-
Puppet::Parser::Functions.function("chomp").should == "function_chomp"
8+
expect(Puppet::Parser::Functions.function("chomp")).to eq("function_chomp")
99
end
1010

1111
it "should raise a ParseError if there is less than 1 arguments" do
12-
lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError))
12+
expect { scope.function_chomp([]) }.to( raise_error(Puppet::ParseError))
1313
end
1414

1515
it "should chomp the end of a string" do
1616
result = scope.function_chomp(["abc\n"])
17-
result.should(eq("abc"))
17+
expect(result).to(eq("abc"))
1818
end
1919
end

spec/functions/chop_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should exist" do
8-
Puppet::Parser::Functions.function("chop").should == "function_chop"
8+
expect(Puppet::Parser::Functions.function("chop")).to eq("function_chop")
99
end
1010

1111
it "should raise a ParseError if there is less than 1 arguments" do
12-
lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError))
12+
expect { scope.function_chop([]) }.to( raise_error(Puppet::ParseError))
1313
end
1414

1515
it "should chop the end of a string" do
1616
result = scope.function_chop(["asdf\n"])
17-
result.should(eq("asdf"))
17+
expect(result).to(eq("asdf"))
1818
end
1919
end

spec/functions/concat_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
66

77
it "should raise a ParseError if the client does not provide two arguments" do
8-
lambda { scope.function_concat([]) }.should(raise_error(Puppet::ParseError))
8+
expect { scope.function_concat([]) }.to(raise_error(Puppet::ParseError))
99
end
1010

1111
it "should raise a ParseError if the first parameter is not an array" do
12-
lambda { scope.function_concat([1, []])}.should(raise_error(Puppet::ParseError))
12+
expect { scope.function_concat([1, []])}.to(raise_error(Puppet::ParseError))
1313
end
1414

1515
it "should be able to concat an array" do
1616
result = scope.function_concat([['1','2','3'],['4','5','6']])
17-
result.should(eq(['1','2','3','4','5','6']))
17+
expect(result).to(eq(['1','2','3','4','5','6']))
1818
end
1919

2020
it "should be able to concat a primitive to an array" do
2121
result = scope.function_concat([['1','2','3'],'4'])
22-
result.should(eq(['1','2','3','4']))
22+
expect(result).to(eq(['1','2','3','4']))
2323
end
2424

2525
it "should not accidentally flatten nested arrays" do
2626
result = scope.function_concat([['1','2','3'],[['4','5'],'6']])
27-
result.should(eq(['1','2','3',['4','5'],'6']))
27+
expect(result).to(eq(['1','2','3',['4','5'],'6']))
2828
end
2929

3030
end

0 commit comments

Comments
 (0)