]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
(maint) Improve test coverage for prefix and suffix
authorAdrien Thebo <git@somethingsinistral.net>
Fri, 20 Dec 2013 22:59:51 +0000 (14:59 -0800)
committerAdrien Thebo <git@somethingsinistral.net>
Fri, 20 Dec 2013 23:03:40 +0000 (15:03 -0800)
spec/unit/puppet/parser/functions/prefix_spec.rb
spec/unit/puppet/parser/functions/suffix_spec.rb

index 5cf592bfba6da1b73913a57506d72f8d798ad323..6e8ddc58ee839b95addd140bc338dceb6f173267 100644 (file)
@@ -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
index c28f719c8e36ad1f18962e3e20aa67a6dfa60783..89ba3b82309126381067259e30480a47045b6af8 100644 (file)
@@ -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