summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Jarvis <leejarvis@fastmail.com>2015-11-25 07:41:27 +0000
committerLee Jarvis <leejarvis@fastmail.com>2015-11-25 07:41:27 +0000
commit8879b402067bb6ee6f98e82c1332c00d17141d58 (patch)
treeb44a4d6e7ad80e6877b36503ac1b1d602f8c814f
parent2c532b9a153ffbb982d67d1297e0e94fb08f7040 (diff)
parent80d5484f99a28b09d745d4d3637aed8a1744a81b (diff)
downloadslop-8879b402067bb6ee6f98e82c1332c00d17141d58.tar.gz
Merge pull request #184 from brbrady/no_prefix_bugfix
Fix bug where true is passed to BoolOption block regardless of --no- prefix
-rw-r--r--lib/slop/types.rb3
-rw-r--r--test/types_test.rb8
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/slop/types.rb b/lib/slop/types.rb
index 672aef3..3848b5e 100644
--- a/lib/slop/types.rb
+++ b/lib/slop/types.rb
@@ -16,7 +16,7 @@ module Slop
def call(value)
self.explicit_value = value
- true
+ !force_false?
end
def value
@@ -92,5 +92,4 @@ module Slop
true
end
end
-
end
diff --git a/test/types_test.rb b/test/types_test.rb
index 5950016..f806c48 100644
--- a/test/types_test.rb
+++ b/test/types_test.rb
@@ -6,7 +6,9 @@ describe Slop::BoolOption do
@verbose = @options.bool "--verbose"
@quiet = @options.bool "--quiet"
@inversed = @options.bool "--inversed", default: true
- @result = @options.parse %w(--verbose --no-inversed)
+ @bloc = @options.bool("--bloc"){|val| (@bloc_val ||= []) << val}
+ @result = @options.parse %w(--verbose --no-inversed
+ --bloc --no-bloc)
end
it "returns true if used" do
@@ -20,6 +22,10 @@ describe Slop::BoolOption do
it "can be inversed via --no- prefix" do
assert_equal false, @result[:inversed]
end
+
+ it "will invert the value passed to &block via --no- prefix" do
+ assert_equal [true, false], @bloc_val
+ end
end
describe Slop::IntegerOption do