diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 08:26:50 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-12-17 08:26:50 +0000 |
commit | f77101e3fef89fd70ae0db3708ce623b7d8d32c1 (patch) | |
tree | 54635808da506585eefe8de2fdda53a3f17498cd /test/types_test.rb | |
parent | 3bd5ec4eabf14dc89a14b285bd5ccf1c0a45d6a5 (diff) | |
download | slop-f77101e3fef89fd70ae0db3708ce623b7d8d32c1.tar.gz |
Add NullOption and default to using it
A NullOption is one whos return value we don't care about. For example,
you might just want a `--version` option which simply prints the
version and exits. In this case, having a `true` value in `to_hash` is
really just noise. We probably don't care about it, using NullOption
discards it.
I think using this for Options#on makes sense because this is logical:
opts.on '--version' do
puts VERSION
exit
end
Rather than:
opts.add '--version' do
puts VERSION
exit
end
And defaulting to a StringOption. This also means you have to be
explicit about adding such an option, which is a good thing.
Diffstat (limited to 'test/types_test.rb')
-rw-r--r-- | test/types_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/types_test.rb b/test/types_test.rb index 44846b1..3696126 100644 --- a/test/types_test.rb +++ b/test/types_test.rb @@ -61,3 +61,18 @@ describe Slop::ArrayOption do end end +describe Slop::NullOption do + before do + @options = Slop::Options.new + @version = @options.null('--version') + @result = @options.parse %w(--version) + end + + it 'has a return value of true' do + assert_equal true, @result[:version] + end + + it 'is not included in to_hash' do + assert_equal({}, @result.to_hash) + end +end |