summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-11-19 07:53:58 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-11-19 07:53:58 +0000
commitb91db74b327848841bee30cbecead14c45e3a260 (patch)
treeaa1551027931886bed6237127ea0af588ab6ac86 /test
parente78399b4841d709ccc02de14c583f92ef8a649ff (diff)
downloadslop-b91db74b327848841bee30cbecead14c45e3a260.tar.gz
Add Options#to_s help string
Diffstat (limited to 'test')
-rw-r--r--test/option_test.rb14
-rw-r--r--test/options_test.rb18
2 files changed, 32 insertions, 0 deletions
diff --git a/test/option_test.rb b/test/option_test.rb
new file mode 100644
index 0000000..606264e
--- /dev/null
+++ b/test/option_test.rb
@@ -0,0 +1,14 @@
+require 'test_helper'
+
+describe Slop::Option do
+ def option(*args)
+ Slop::Option.new(*args)
+ end
+
+ describe "#flag" do
+ it "returns the flags joined by a comma" do
+ assert_equal "-f, --bar", option(%w(-f --bar), nil).flag
+ assert_equal "--bar", option(%w(--bar), nil).flag
+ end
+ end
+end
diff --git a/test/options_test.rb b/test/options_test.rb
index 97c45d9..3ce0863 100644
--- a/test/options_test.rb
+++ b/test/options_test.rb
@@ -53,4 +53,22 @@ describe Slop::Options do
assert @options.respond_to?(:bar)
end
end
+
+ describe "#to_s" do
+ it "is prefixed with the banner" do
+ assert_match(/^usage/, @options.to_s)
+ end
+
+ it "aligns option strings" do
+ @options.add "-f", "--foo", "fooey"
+ @options.add "-s", "short"
+ assert_match(/^ -f, --foo fooey/, @options.to_s)
+ assert_match(/^ -s short/, @options.to_s)
+ end
+
+ it "can use a custom prefix" do
+ @options.add "-f", "--foo"
+ assert_match(/^ -f, --foo/, @options.to_s(prefix: " "))
+ end
+ end
end