From fbcd397f5e9acd4b90fe9f5a9ccf692f172456ca Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 25 Aug 2011 11:57:27 -0700 Subject: CHEF-1563: required options always fail --- spec/mixlib/cli_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec') diff --git a/spec/mixlib/cli_spec.rb b/spec/mixlib/cli_spec.rb index aaa2d3a..9eed069 100644 --- a/spec/mixlib/cli_spec.rb +++ b/spec/mixlib/cli_spec.rb @@ -175,6 +175,27 @@ describe Mixlib::CLI do lambda { @cli.parse_options([]) }.should raise_error(SystemExit) end + it "should not exit if a required option is specified" do + TestCLI.option(:require_me, :short => "-r", :boolean => true, :required => true) + @cli = TestCLI.new + @cli.parse_options(["-r"]) + @cli.config[:require_me].should == true + end + + it "should not exit if a required boolean option is specified and false" do + TestCLI.option(:require_me, :long => "--[no-]req", :boolean => true, :required => true) + @cli = TestCLI.new + @cli.parse_options(["--no-req"]) + @cli.config[:require_me].should == false + end + + it "should not exit if a required option is specified and empty" do + TestCLI.option(:require_me, :short => "-r VALUE", :required => true) + @cli = TestCLI.new + @cli.parse_options(["-r", ""]) + @cli.config[:require_me].should == "" + end + it "should preserve all of the commandline arguments, ARGV" do TestCLI.option(:config_file, :short => "-c CONFIG") @cli = TestCLI.new -- cgit v1.2.1