diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-01 15:16:55 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-04 13:32:04 -0700 |
commit | 8b37d7038c89bd830b076e838686419ff0068b56 (patch) | |
tree | 85e7f23ab1aeca93d24290d779339fb0ebecb784 /spec | |
parent | 37c97cdca07fd8c446e924547239c8f09eda8810 (diff) | |
download | puppet-8b37d7038c89bd830b076e838686419ff0068b56.tar.gz puppet-8b37d7038c89bd830b076e838686419ff0068b56.tar.xz puppet-8b37d7038c89bd830b076e838686419ff0068b56.zip |
(#6749) Polish the CLI option pre-parse implementation
This improves handling of the pre-parse of the command line to be
non-destructive, which cuts down the volume of garbage generated in the
process.
It also improves testing to verify that we get the darn thing right...
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/unit/application/string_base_spec.rb | 65 |
1 files changed, 16 insertions, 49 deletions
diff --git a/spec/unit/application/string_base_spec.rb b/spec/unit/application/string_base_spec.rb index 20185b526..62869fe61 100755 --- a/spec/unit/application/string_base_spec.rb +++ b/spec/unit/application/string_base_spec.rb @@ -16,6 +16,11 @@ describe Puppet::Application::StringBase do File.open(File.join(@dir, 'puppet', 'string', 'basetest.rb'), 'w') do |f| f.puts "Puppet::String.define(:basetest, '0.0.1')" end + + Puppet::String[:basetest, '0.0.1'].action :foo do + option "--foo" + invoke { |*args| args.length } + end end after :all do @@ -28,7 +33,6 @@ describe Puppet::Application::StringBase do app.stubs(:exit) app.stubs(:puts) app.command_line.stubs(:subcommand_name).returns 'subcommand' - app.command_line.stubs(:args).returns [] Puppet::Util::Log.stubs(:newdestination) app end @@ -39,13 +43,6 @@ describe Puppet::Application::StringBase do end describe "parsing the command line" do - before :all do - Puppet::String[:basetest, '0.0.1'].action :foo do - option "--foo" - invoke { |options| options } - end - end - context "with just an action" do before :all do app.command_line.stubs(:args).returns %w{foo} @@ -99,52 +96,22 @@ describe Puppet::Application::StringBase do end end - describe "when calling main" do - # before do - # @app.verb = :find - # @app.arguments = ["myname", "myarg"] - # @app.string.stubs(:find) - # end - - it "should send the specified verb and name to the string" do - pending "REVISIT: disabled, needs to be rewritten for the new introspection model. --daniel 2011-03-31" - @app.string.expects(:find).with("myname", "myarg") - app.main - end - - it "should use its render method to render any result" - - it "should exit with the current exit code" - end - - describe "during setup" do + describe "#main" do before do - app.command_line.stubs(:args).returns(["find", "myname", "myarg"]) - app.stubs(:validate) - end - - it "should set the verb from the command line arguments" do - pending "REVISIT: needs updating too..." - - @app.setup - @app.verb.should == "find" + app.string = Puppet::String[:basetest, '0.0.1'] + app.action = app.string.get_action(:foo) + app.format = :pson + app.arguments = ["myname", "myarg"] end - it "should make sure arguments are an array" do - pending "REVISIT: needs updating too..." - - @app.command_line.stubs(:args).returns(["find", "myname", "myarg"]) - @app.setup - @app.arguments.should == ["myname", "myarg", {}] + it "should send the specified verb and name to the string" do + app.string.expects(:foo).with(*app.arguments) + app.main end - it "should pass options as the last argument" do - pending "REVISIT: needs updating too..." - - @app.command_line.stubs(:args).returns(["find", "myname", "myarg", "--foo"]) - @app.parse_options - @app.setup - @app.arguments.should == ["myname", "myarg", { :foo => true }] + it "should use its render method to render any result" do + app.expects(:render).with(app.arguments.length + 1) + app.main end end end |