diff options
author | Lee Jarvis <lee@jrvs.uk> | 2023-02-15 11:28:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-15 11:28:21 -0800 |
commit | 2410f313984be1dfe73884251e879b008771535d (patch) | |
tree | 8f36d5b4c65685653e0c8ef3c344d5fe75564fd6 /test/error_test.rb | |
parent | fc4622fc08d7982847ff583ad691ee4ba47f63f8 (diff) | |
parent | becc0305239c2885affb1f57419afac3e5418a88 (diff) | |
download | slop-2410f313984be1dfe73884251e879b008771535d.tar.gz |
Merge pull request #278 from heyvito/feat/validate-types
Add support to optional type validation
Diffstat (limited to 'test/error_test.rb')
-rw-r--r-- | test/error_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/error_test.rb b/test/error_test.rb index d9c71ab..8ea9069 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -63,3 +63,18 @@ describe Slop::MissingRequiredOption do opts.parse [] end end + +describe Slop::InvalidOptionValue do + it "raises when an option has an invalid value" do + opts = Slop::Options.new(validate_types: true) + opts.integer "-n", "--number", default: 10 + assert_raises(Slop::InvalidOptionValue) { opts.parse %w(-n foo) } + end + + it "does not raise when errors are suppressed" do + opts = Slop::Options.new(suppress_errors: true) + opts.integer "-n", "--number", default: 10, validate_type: true + r = opts.parse %w(-n foo) + assert_equal(10, r[:n]) + end +end |