diff options
author | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 09:26:41 +0000 |
---|---|---|
committer | Lee Jarvis <ljjarvis@gmail.com> | 2014-11-19 09:26:41 +0000 |
commit | 63d1212fd21e783912cc158e4decae5c6c94642c (patch) | |
tree | 6cd227929ebdabccc59184b0d40c3cfcb20c4340 /test | |
parent | 253dcd9622328d5f7a5a695c3bf487b65565fb9e (diff) | |
download | slop-63d1212fd21e783912cc158e4decae5c6c94642c.tar.gz |
Add Result#to_hash
Diffstat (limited to 'test')
-rw-r--r-- | test/option_test.rb | 10 | ||||
-rw-r--r-- | test/result_test.rb | 18 |
2 files changed, 28 insertions, 0 deletions
diff --git a/test/option_test.rb b/test/option_test.rb index 606264e..399d5c5 100644 --- a/test/option_test.rb +++ b/test/option_test.rb @@ -11,4 +11,14 @@ describe Slop::Option do assert_equal "--bar", option(%w(--bar), nil).flag end end + + describe "#key" do + it "uses the last flag and strips trailing hyphens" do + assert_equal :foo, option(%w(-f --foo), nil).key + end + + it "can be overridden" do + assert_equal :bar, option(%w(-f --foo), nil, key: "bar").key + end + end end diff --git a/test/result_test.rb b/test/result_test.rb new file mode 100644 index 0000000..719978b --- /dev/null +++ b/test/result_test.rb @@ -0,0 +1,18 @@ +require 'test_helper' + +describe Slop::Result do + before do + @options = Slop::Options.new + @options.bool "-v", "--verbose" + @options.string "--name" + @options.string "--unused" + + @result = @options.parse %w(foo -v --name lee argument) + end + + describe "#to_hash" do + it "returns option keys and values" do + assert_equal({ verbose: true, name: "lee", unused: nil }, @result.to_hash) + end + end +end |