summaryrefslogtreecommitdiff
path: root/test/options_test.rb
diff options
context:
space:
mode:
authorLee Jarvis <ljjarvis@gmail.com>2014-11-18 22:16:20 +0000
committerLee Jarvis <ljjarvis@gmail.com>2014-11-18 22:29:15 +0000
commite78399b4841d709ccc02de14c583f92ef8a649ff (patch)
tree012575c9523f7e8ba712d8421f189e0aec5ed65e /test/options_test.rb
parentc67a27c4b7554cbf66536e5bcebed60ff4cc7feb (diff)
downloadslop-e78399b4841d709ccc02de14c583f92ef8a649ff.tar.gz
Start of rewrite
Diffstat (limited to 'test/options_test.rb')
-rw-r--r--test/options_test.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/options_test.rb b/test/options_test.rb
new file mode 100644
index 0000000..97c45d9
--- /dev/null
+++ b/test/options_test.rb
@@ -0,0 +1,56 @@
+require 'test_helper'
+
+describe Slop::Options do
+ before do
+ @options = Slop::Options.new
+ end
+
+ describe "#add" do
+ it "defaults to string type" do
+ assert_kind_of Slop::StringOption, @options.add("--foo")
+ end
+
+ it "accepts custom types" do
+ module Slop; class FooOption < Option; end; end
+ assert_kind_of Slop::FooOption, @options.add("--foo", type: :foo)
+ end
+
+ it "adds multiple flags" do
+ option = @options.add("-f", "-F", "--foo")
+ assert_equal %w(-f -F --foo), option.flags
+ end
+
+ it "accepts a trailing description" do
+ option = @options.add("--foo", "fooey")
+ assert_equal "fooey", option.desc
+ end
+
+ it "adds the option" do
+ option = @options.add("--foo")
+ assert_equal [option], @options.to_a
+ end
+
+ it "raises an error when a duplicate flag is used" do
+ @options.add("--foo")
+ assert_raises(ArgumentError) { @options.add("--foo") }
+ end
+ end
+
+ describe "#method_missing" do
+ it "uses the method name as an option type" do
+ option = @options.string("--name")
+ assert_kind_of Slop::StringOption, option
+ end
+
+ it "raises if a type doesn't exist" do
+ assert_raises(NoMethodError) { @options.unknown }
+ end
+ end
+
+ describe "#respond_to?" do
+ it "handles custom types" do
+ module Slop; class BarOption < Option; end; end
+ assert @options.respond_to?(:bar)
+ end
+ end
+end