diff options
author | Yuri Zubov <y.zubov@sumatosoft.com> | 2018-03-23 14:54:59 +0300 |
---|---|---|
committer | Yuri Zubov <y.zubov@sumatosoft.com> | 2018-03-23 16:16:23 +0300 |
commit | f0861cf9036e75111b6ac62fa9bd2a4d0b6ad3a6 (patch) | |
tree | c13a6a7836645b2ffedfd28463b33b8678dcdc03 /spec/mixlib | |
parent | 6fcb76e55b15dd9e80925a7512115739e1938230 (diff) | |
download | mixlib-cli-f0861cf9036e75111b6ac62fa9bd2a4d0b6ad3a6.tar.gz |
bugfix: if param :required is set to false and param :in is set the option is required
Signed-off-by: Yuri Zubov <y.zubov@sumatosoft.com>
Diffstat (limited to 'spec/mixlib')
-rw-r--r-- | spec/mixlib/cli_spec.rb | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index 4db841c..20d3285 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -185,27 +185,47 @@ describe Mixlib::CLI do expect(lambda { @cli.parse_options([]) }).to raise_error(SystemExit) end - it "exits if option is not included in the list" do - TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}) + it "exits if option is not included in the list and required" do + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true) @cli = TestCLI.new expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(SystemExit) end + it "exits if option is not included in the list and not required" do + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => false) + @cli = TestCLI.new + expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(SystemExit) + end + + it "doesn't exit if option is nil and not required" do + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => false) + @cli = TestCLI.new + expect do + expect(@cli.parse_options([])).to eql [] + end.to_not raise_error + end + + it "exit if option is nil and required" do + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true) + @cli = TestCLI.new + expect(lambda { @cli.parse_options([]) }).to raise_error(SystemExit) + end + it "raises ArgumentError if options key :in is not an array" do - TestCLI.option(:inclusion, :short => "-i val", :in => "foo") + TestCLI.option(:inclusion, :short => "-i val", :in => "foo", :required => true) @cli = TestCLI.new expect(lambda { @cli.parse_options(["-i", "three"]) }).to raise_error(ArgumentError) end it "doesn't exit if option is included in the list" do - TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}) + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :required => true) @cli = TestCLI.new @cli.parse_options(["-i", "one"]) expect(@cli.config[:inclusion]).to eql("one") end it "changes description if :in key is specified" do - TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :description => "desc") + TestCLI.option(:inclusion, :short => "-i val", :in => %w{one two}, :description => "desc", :required => false) @cli = TestCLI.new @cli.parse_options(["-i", "one"]) expect(@cli.options[:inclusion][:description]).to eql("desc (included in ['one', 'two'])") |