]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
enhanced the error message of pick function.
authorLeonardo Rodrigues de Mello <l@lmello.eu.org>
Fri, 6 Sep 2013 13:53:47 +0000 (10:53 -0300)
committerLeonardo Rodrigues de Mello <l@lmello.eu.org>
Mon, 16 Sep 2013 13:03:20 +0000 (10:03 -0300)
When pick function fail return a better error message like
the other stdlib functions, indicating that the error
is on function pick.

This would help people that see the error to identity it is
related to a incorrect use of stdlib function pick, instead of having
to grep all puppet libraries and manifests source for the old message.

I had also changed the spec test.

pick function change spec  as suggested GH-179

Fix the spec test to use expect {}.to instead of lambda {}.should
as explained by Adrienthebo.

"Using expect { }.to is preferred over lambda { }.should.
 In addition it's best practice to do a string match against the
error message to ensure that we're catching the right error,
instead of any error of the right type."

Also fixed a typo on the error message, it was missing one space.

pick function stylish fix as suggested on GH179

lib/puppet/parser/functions/pick.rb
spec/unit/puppet/parser/functions/pick_spec.rb

index cbc030021a8a53389342bf1b0df55a104e295851..e9e5d66a8608a36488f7e589ea7b1c3c17e37a42 100644 (file)
@@ -21,7 +21,7 @@ EOS
    args.delete(:undefined)
    args.delete("")
    if args[0].to_s.empty? then
-     fail "Must provide non empty value."
+     fail Puppet::ParseError, "pick(): must receive at last one non empty value"
    else
      return args[0]
    end
index 761db6be2104fb521af74190d3a4adce55ede63a..d2b275f62b8a4c7fa12728aa958a62950831352d 100644 (file)
@@ -29,6 +29,6 @@ describe "the pick function" do
   end
 
   it 'should error if no values are passed' do
-    expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./)
+    expect { scope.function_pick([]) }.to( raise_error(Puppet::ParseError, "pick(): must receive at last one non empty value"))
   end
 end