summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTim Rogers <tim@gocardless.com>2015-06-13 18:40:32 +0100
committerTim Rogers <tim@gocardless.com>2015-06-13 18:40:32 +0100
commitfd0e2d8bc3d1c647e6b051f48b8bedbe77934c0c (patch)
tree38105cadafc1b4f0609121b1d2f043af46ed4425 /test
parent1a075c05d38be0df849119530378043994c05c91 (diff)
downloadslop-fd0e2d8bc3d1c647e6b051f48b8bedbe77934c0c.tar.gz
Better handling of option names with multiple words
Diffstat (limited to 'test')
-rw-r--r--test/option_test.rb4
-rw-r--r--test/result_test.rb20
2 files changed, 18 insertions, 6 deletions
diff --git a/test/option_test.rb b/test/option_test.rb
index 399d5c5..78fd55e 100644
--- a/test/option_test.rb
+++ b/test/option_test.rb
@@ -17,6 +17,10 @@ describe Slop::Option do
assert_equal :foo, option(%w(-f --foo), nil).key
end
+ it "converts dashes to underscores to make multi-word options symbol-friendly" do
+ assert_equal :foo_bar, option(%w(-f --foo-bar), nil).key
+ end
+
it "can be overridden" do
assert_equal :bar, option(%w(-f --foo), nil, key: "bar").key
end
diff --git a/test/result_test.rb b/test/result_test.rb
index 760f460..0efdfff 100644
--- a/test/result_test.rb
+++ b/test/result_test.rb
@@ -12,16 +12,18 @@ end
describe Slop::Result do
before do
- @options = Slop::Options.new
- @verbose = @options.bool "-v", "--verbose"
- @name = @options.string "--name"
- @unused = @options.string "--unused"
- @result = @options.parse %w(foo -v --name lee argument)
+ @options = Slop::Options.new
+ @verbose = @options.bool "-v", "--verbose"
+ @name = @options.string "--name"
+ @unused = @options.string "--unused"
+ @long_option = @options.string "--long-option"
+ @result = @options.parse %w(foo -v --name lee --long-option bar argument)
end
it "increments option count" do
# test this here so it's more "full stack"
assert_equal 1, @verbose.count
+ assert_equal 1, @long_option.count
@result.parser.parse %w(-v --verbose)
assert_equal 2, @verbose.count
end
@@ -51,6 +53,9 @@ describe Slop::Result do
assert_equal "lee", @result["name"]
assert_equal "lee", @result[:name]
assert_equal "lee", @result["--name"]
+ assert_equal "bar", @result["long_option"]
+ assert_equal "bar", @result[:long_option]
+ assert_equal "bar", @result["--long-option"]
end
end
@@ -72,6 +77,7 @@ describe Slop::Result do
it "checks if options have been used" do
assert_equal true, @result.verbose?
assert_equal false, @result.unused?
+ assert_equal true, @result.long_option?
end
end
@@ -79,6 +85,7 @@ describe Slop::Result do
it "returns an option by flag" do
assert_equal @verbose, @result.option("--verbose")
assert_equal @verbose, @result.option("-v")
+ assert_equal @long_option, @result.option("--long-option")
end
it "ignores prefixed hyphens" do
@@ -93,7 +100,8 @@ describe Slop::Result do
describe "#to_hash" do
it "returns option keys and values" do
- assert_equal({ verbose: true, name: "lee", unused: nil }, @result.to_hash)
+ assert_equal({ verbose: true, name: "lee", unused: nil, long_option: "bar" },
+ @result.to_hash)
end
end
end