From 7991dd20738209ab86a657ba62f2600ba39ca8ef Mon Sep 17 00:00:00 2001 From: Franco Catena Date: Thu, 5 Dec 2013 16:11:59 -0300 Subject: Fix prefix exception message (Closes #23364) --- lib/puppet/parser/functions/prefix.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb index 62211ae..d02286a 100644 --- a/lib/puppet/parser/functions/prefix.rb +++ b/lib/puppet/parser/functions/prefix.rb @@ -28,7 +28,7 @@ Will return: ['pa','pb','pc'] if prefix unless prefix.is_a?(String) - raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}" + raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{prefix.inspect}" end end -- cgit v1.2.3 From 7085472e69569abf67862dfdd4263e8754afb89b Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Fri, 20 Dec 2013 14:59:51 -0800 Subject: (maint) Improve test coverage for prefix and suffix --- spec/unit/puppet/parser/functions/prefix_spec.rb | 19 ++++++++++++++----- spec/unit/puppet/parser/functions/suffix_spec.rb | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/spec/unit/puppet/parser/functions/prefix_spec.rb b/spec/unit/puppet/parser/functions/prefix_spec.rb index 5cf592b..6e8ddc5 100644 --- a/spec/unit/puppet/parser/functions/prefix_spec.rb +++ b/spec/unit/puppet/parser/functions/prefix_spec.rb @@ -4,15 +4,24 @@ require 'spec_helper' describe "the prefix function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("prefix").should == "function_prefix" + it "raises a ParseError if there is less than 1 arguments" do + expect { scope.function_prefix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) end - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) + it "raises an error if the first argument is not an array" do + expect { + scope.function_prefix([Object.new]) + }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) end - it "should return a prefixed array" do + + it "raises an error if the second argument is not a string" do + expect { + scope.function_prefix([['first', 'second'], 42]) + }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) + end + + it "returns a prefixed array" do result = scope.function_prefix([['a','b','c'], 'p']) result.should(eq(['pa','pb','pc'])) end diff --git a/spec/unit/puppet/parser/functions/suffix_spec.rb b/spec/unit/puppet/parser/functions/suffix_spec.rb index c28f719..89ba3b8 100644 --- a/spec/unit/puppet/parser/functions/suffix_spec.rb +++ b/spec/unit/puppet/parser/functions/suffix_spec.rb @@ -4,15 +4,23 @@ require 'spec_helper' describe "the suffix function" do let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - it "should exist" do - Puppet::Parser::Functions.function("suffix").should == "function_suffix" + it "raises a ParseError if there is less than 1 arguments" do + expect { scope.function_suffix([]) }.to raise_error(Puppet::ParseError, /number of arguments/) end - it "should raise a ParseError if there is less than 1 arguments" do - lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError)) + it "raises an error if the first argument is not an array" do + expect { + scope.function_suffix([Object.new]) + }.to raise_error(Puppet::ParseError, /expected first argument to be an Array/) end - it "should return a suffixed array" do + it "raises an error if the second argument is not a string" do + expect { + scope.function_suffix([['first', 'second'], 42]) + }.to raise_error(Puppet::ParseError, /expected second argument to be a String/) + end + + it "returns a suffixed array" do result = scope.function_suffix([['a','b','c'], 'p']) result.should(eq(['ap','bp','cp'])) end -- cgit v1.2.3