Skip to content

Commit

Permalink
Change formatting of a hash value in parameter validation error message
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrmurach committed Jul 5, 2022
1 parent e6a5f87 commit 7c9a30d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

### Changed
* Change permit setting to work with parameters converted to an array or a hash
* Change formatting of a hash value in parameter validation error message

### Fixed
* Fix argument check against permitted values to allow nil value when optional
Expand Down
2 changes: 1 addition & 1 deletion lib/tty/option/errors.rb
Expand Up @@ -55,7 +55,7 @@ def initialize(param_or_message, value = nil)
@param = param_or_message

message = format(MESSAGE,
value: value,
value: format_value(value),
name: param.name,
type: param.to_sym)
else
Expand Down
17 changes: 16 additions & 1 deletion spec/unit/parse_spec.rb
Expand Up @@ -201,7 +201,7 @@
expect {
cmd.parse(%w[a:1 b:2 c:3], raise_on_parse_error: true)
}.to raise_error(TTY::Option::InvalidArgument,
"value of `[:c, 3]` fails validation for 'foo' argument")
"value of `c:3` fails validation for 'foo' argument")
end

it "doesn't raise on a validation rule failure and reads an error message" do
Expand Down Expand Up @@ -816,6 +816,21 @@
}.to raise_error(TTY::Option::InvalidArgument,
"value of `12` fails validation for '--foo' option")
end

it "validates an option given as multiple argument pairs" do
cmd = new_command do
option :foo do
long "--foo VAL"
convert :int_map
validate(->(val) { val[1] < 12 })
end
end

expect {
cmd.parse(%w[--foo a:11 b:12 c:13], raise_on_parse_error: true)
}.to raise_error(TTY::Option::InvalidArgument,
"value of `b:12` fails validation for '--foo' option")
end
end
end

Expand Down

0 comments on commit 7c9a30d

Please sign in to comment.