diff options
author | Lee Jarvis <lee@jarvis.co> | 2011-03-16 16:49:38 +0000 |
---|---|---|
committer | Lee Jarvis <lee@jarvis.co> | 2011-03-16 16:49:38 +0000 |
commit | 20e36b3f9478a58ea9c4b10c729a7f670ec45534 (patch) | |
tree | 02d7ae21ced8d97c9522002323e0c10d33b13c12 | |
parent | c9cf0aaadc4d96d75bf5834884fa43fd21b3c04b (diff) | |
download | slop-20e36b3f9478a58ea9c4b10c729a7f670ec45534.tar.gz |
argument_value should be nil if the option expects an argument and none is given, added tests
-rw-r--r-- | lib/slop.rb | 1 | ||||
-rw-r--r-- | test/option_test.rb | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/slop.rb b/lib/slop.rb index 198483b..40f5d55 100644 --- a/lib/slop.rb +++ b/lib/slop.rb @@ -109,6 +109,7 @@ private option.argument_value = argument option.callback.call(option.argument_value) if option.has_callback? else + option.argument_value = nil if option.accepts_optional_argument? option.callback.call(nil) if option.has_callback? else diff --git a/test/option_test.rb b/test/option_test.rb index ca34b2a..1b7825a 100644 --- a/test/option_test.rb +++ b/test/option_test.rb @@ -77,4 +77,11 @@ class OptionTest < TestCase assert_equal " --age Your age", slop.options[:age].to_s assert_equal " -V, Display the version", slop.options[:V].to_s end + + test 'falls back to default option' do + slop = Slop.new + slop.opt :foo, :optional => true, :default => 'lee' + slop.parse %w/--foo/ + assert_equal 'lee', slop[:foo] + end end |