diff options
author | Mehrez Alachheb <mehrez.alachheb@inria.fr> | 2013-06-15 22:55:44 +0200 |
---|---|---|
committer | Mehrez Alachheb <mehrez.alachheb@inria.fr> | 2013-06-15 22:55:44 +0200 |
commit | 94e5b7f860d5acacb75653a0ec2f876a197ebdf7 (patch) | |
tree | 1d954f5ea3753f84983da005f691abfcb3ba3398 /spec | |
parent | 83e161811cbe483759790d737229efbca2f93021 (diff) | |
download | mixlib-cli-94e5b7f860d5acacb75653a0ec2f876a197ebdf7.tar.gz |
Add option key ':in' to specifie that option value should be included in the given list
Diffstat (limited to 'spec')
-rw-r--r-- | spec/mixlib/cli_spec.rb | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index 39740b4..e2fa647 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -79,7 +79,8 @@ describe Mixlib::CLI do :required => false, :proc => nil, :show_options => false, - :exit => nil + :exit => nil, + :in => nil } } end @@ -174,6 +175,32 @@ describe Mixlib::CLI do @cli = TestCLI.new lambda { @cli.parse_options([]) }.should raise_error(SystemExit) end + + it "should exit if option is not included in the list" do + TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two']) + @cli = TestCLI.new + lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(SystemExit) + end + + it "should exit if options key :in is not an array" do + TestCLI.option(:inclusion, :short => "-i val", :in => 'foo') + @cli = TestCLI.new + lambda { @cli.parse_options(['-i', 'three']) }.should raise_error(ArgumentError) + end + + it "should not exit if option is included in the list" do + TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two']) + @cli = TestCLI.new + @cli.parse_options(['-i', 'one']) + @cli.config[:inclusion].should == 'one' + end + + it "should change description if :in key is specified" do + TestCLI.option(:inclusion, :short => "-i val", :in => ['one', 'two'], :description => 'desc') + @cli = TestCLI.new + @cli.parse_options(['-i', 'one']) + @cli.options[:inclusion][:description].should == "desc (included in [\"one\", \"two\"])" + end it "should not exit if a required option is specified" do TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true) |