diff options
author | William Woodruff <william@tuffbizz.com> | 2017-09-29 18:31:28 -0400 |
---|---|---|
committer | William Woodruff <william@tuffbizz.com> | 2017-09-29 18:55:49 -0400 |
commit | 311cb9fbe94fe09c0dc08a52f5bff169529960ba (patch) | |
tree | 8eb7c8bcba2f7210e47b393dd200c2423dab82c0 /test | |
parent | ec47929b2ffe986b13701c30f1bbe3018593bc6c (diff) | |
download | slop-311cb9fbe94fe09c0dc08a52f5bff169529960ba.tar.gz |
Support for required options
This commit introduces support for required options,
which are options that cause the parser to raise
a `MissingRequiredOption` exception if not present.
Options can be marked as required by passing
`required: true` in their configuration, and any errors
caused by missing required options can be suppressed via
`suppress_errors: true`.
Diffstat (limited to 'test')
-rw-r--r-- | test/error_test.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/error_test.rb b/test/error_test.rb index 2f7730b..d9c71ab 100644 --- a/test/error_test.rb +++ b/test/error_test.rb @@ -49,3 +49,17 @@ describe Slop::UnknownOption do opts.parse %w(--foo) end end + +describe Slop::MissingRequiredOption do + it "raises when a required option is missing" do + opts = Slop::Options.new + opts.string "-n", "--name", required: true + assert_raises(Slop::MissingRequiredOption) { opts.parse [] } + end + + it "does not raise when errors are suppressed" do + opts = Slop::Options.new(suppress_errors: true) + opts.string "-n", "--name", required: true + opts.parse [] + end +end |