diff options
author | Olle Jonsson <olle.jonsson@gmail.com> | 2018-06-27 23:03:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-27 23:03:49 +0200 |
commit | 45a66b049a1fa9953f51e4ff5583a76ea6e89647 (patch) | |
tree | a038f3e2e64f19e0cdadc0dc165e1371c2fb9b5e /test | |
parent | 3c8d14df8c312f5bfd4461202d782ef927462476 (diff) | |
parent | 0b6d52e1f2f045f9678ac929c1c942cc6f356f45 (diff) | |
download | slop-45a66b049a1fa9953f51e4ff5583a76ea6e89647.tar.gz |
Merge pull request #232 from giovannibenussi/add-result-fetch
Add Slop::Result#fetch
Diffstat (limited to 'test')
-rw-r--r-- | test/result_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/result_test.rb b/test/result_test.rb index 322daa1..30e4934 100644 --- a/test/result_test.rb +++ b/test/result_test.rb @@ -62,6 +62,31 @@ describe Slop::Result do end end + describe "#fetch" do + it "returns an options value" do + assert_equal "lee", @result.fetch("--name") + end + + it "raises Slop::UnknownOption when an option does not exists" do + e = assert_raises(Slop::UnknownOption) { @result.fetch("--unexisting") } + assert_equal "option not found: 'unexisting'", e.message + end + + it "returns the default value of an option when a value is not provided" do + @options.string("--foo", default: "bar") + @result.parser.parse %w(--foo) + + assert_equal 'bar', @result.fetch('foo') + end + + it "returns nil when an option is not provided and it does not have a default value" do + @options.string("--hello") + @result.parser.parse %w() + + assert_equal nil, @result.fetch('hello') + end + end + describe "#[]=" do it "sets an options value" do assert_equal "lee", @result["name"] |