diff options
author | Lee Jarvis <leejarvis@fastmail.com> | 2017-11-17 23:37:52 +0000 |
---|---|---|
committer | Lee Jarvis <leejarvis@fastmail.com> | 2017-11-17 23:37:52 +0000 |
commit | 6e30144e8bbe013d80384c3ef095368a782df1ed (patch) | |
tree | 7cb131285f430d3bf95a35a76b360cd14228fd74 | |
parent | d021364d5a2dc3a6b22953be215f332b3fde23b7 (diff) | |
download | slop-6e30144e8bbe013d80384c3ef095368a782df1ed.tar.gz |
Add more tests for Options#separator
And fixed the inevitable missed last separator..
Fixes #222
-rw-r--r-- | lib/slop/options.rb | 4 | ||||
-rw-r--r-- | test/options_test.rb | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/slop/options.rb b/lib/slop/options.rb index 41913e0..3a1e429 100644 --- a/lib/slop/options.rb +++ b/lib/slop/options.rb @@ -111,6 +111,10 @@ module Slop str << "#{prefix}#{opt.to_s(offset: len)}\n" end + if sep = separators[options.size] + str << "#{sep}\n" + end + str end diff --git a/test/options_test.rb b/test/options_test.rb index 8553fe1..3ef34c5 100644 --- a/test/options_test.rb +++ b/test/options_test.rb @@ -37,7 +37,28 @@ describe Slop::Options do end describe "#separator" do - # TODO: Missing all other specs for #separator + it "appends separators between options in order" do + @options.separator("foo") + @options.on("--foo") + @options.separator("bar") + + assert_equal ["foo", "bar"], @options.separators + end + + it "appends strings to the last separator if no options exist" do + @options.separator("foo") + @options.separator("bar") + + assert_equal ["foo\nbar"], @options.separators + end + + it "includes separators in the help text" do + @options.on("--foo") + @options.separator("bar") + + help = @options.to_s.squeeze(" ") + assert help.end_with?("--foo \nbar\n") + end it "accepts a frozen argument, even when called multiple times for the same option" do @options.separator("foo".freeze) |