Skip to content

enhanced the error message of pick function. #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/pick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Puppet::Parser::Functions
args.delete(:undefined)
args.delete("")
if args[0].to_s.empty? then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI Adrien,

I will revert to the previous layout. Will only change the message and the call to fail to raise the correct exception.
Puppet::ParseError

Is that correct ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be perfect, yes.

fail "Must provide non empty value."
fail Puppet::ParseError, "pick(): must receive at last one non empty value"
else
return args[0]
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/parser/functions/pick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining! I will change that.

end
end