diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2010-04-30 14:54:07 -0700 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 76304f8b09ec7d47b5ebd75efde8499a1e3ca63c (patch) | |
| tree | 1f1535d5a74c3d647e3cb90580a9c28dba3f254a /spec | |
| parent | e9627a060619eaf0f8eeb012979dddb047c6648e (diff) | |
feature #2276 Single Executable: move CommandLine methods
move Util::CommandLine methods into instances instead of on the class,
as suggested by Markus
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/unit/util/command_line.rb | 85 |
1 files changed, 29 insertions, 56 deletions
diff --git a/spec/unit/util/command_line.rb b/spec/unit/util/command_line.rb index e20f51a99..7413e57d1 100644 --- a/spec/unit/util/command_line.rb +++ b/spec/unit/util/command_line.rb @@ -12,102 +12,75 @@ describe Puppet::Util::CommandLine do end it "should pull off the first argument if it looks like a subcommand" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( client --help whatever.pp ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( client --help whatever.pp ), @tty ) - command.should == "client" - args.should == %w( --help whatever.pp ) + command_line.subcommand_name.should == "client" + command_line.args.should == %w( --help whatever.pp ) end it "should use 'apply' if the first argument looks like a .pp file" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( whatever.pp ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( whatever.pp ), @tty ) - command.should == "apply" - args.should == %w( whatever.pp ) + command_line.subcommand_name.should == "apply" + command_line.args.should == %w( whatever.pp ) end it "should use 'apply' if the first argument looks like a .rb file" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( whatever.rb ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( whatever.rb ), @tty ) - command.should == "apply" - args.should == %w( whatever.rb ) + command_line.subcommand_name.should == "apply" + command_line.args.should == %w( whatever.rb ) end it "should use 'apply' if the first argument looks like a flag" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( --debug ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( --debug ), @tty ) - command.should == "apply" - args.should == %w( --debug ) + command_line.subcommand_name.should == "apply" + command_line.args.should == %w( --debug ) end it "should use 'apply' if the first argument is -" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( - ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( - ), @tty ) - command.should == "apply" - args.should == %w( - ) + command_line.subcommand_name.should == "apply" + command_line.args.should == %w( - ) end it "should return nil if the first argument is --help" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", %w( --help ), @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", %w( --help ), @tty ) - command.should == nil + command_line.subcommand_name.should == nil end it "should return nil if there are no arguments on a tty" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", [], @tty ) + command_line = Puppet::Util::CommandLine.new("puppet", [], @tty ) - command.should == nil - args.should == [] + command_line.subcommand_name.should == nil + command_line.args.should == [] end it "should use 'apply' if there are no arguments on a pipe" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppet", [], @pipe ) + command_line = Puppet::Util::CommandLine.new("puppet", [], @pipe ) - command.should == "apply" - args.should == [] - end - - it "should provide a convenience method that only returns the subcommand" do - Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", [], @pipe ).returns(["command", ['args']]) - command = Puppet::Util::CommandLine.subcommand_name( "puppet", [], @pipe ) - command.should == "command" - end - - it "should provide a convenience method that only returns the args" do - Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", [], @pipe ).returns(["command", ['args']]) - args = Puppet::Util::CommandLine.args( "puppet", [], @pipe ) - args.should == ['args'] + command_line.subcommand_name.should == "apply" + command_line.args.should == [] end it "should return the executable name if it is not puppet" do - command, args = Puppet::Util::CommandLine.subcommand_and_args("puppetmasterd", [], @tty ) + command_line = Puppet::Util::CommandLine.new("puppetmasterd", [], @tty ) - command.should == "puppetmasterd" + command_line.subcommand_name.should == "puppetmasterd" end it "should translate subcommand names into their legacy equivalent" do - Puppet::Util::CommandLine.legacy_executable_name("puppet", ["master"], @tty).should == "puppetmasterd" + command_line = Puppet::Util::CommandLine.new("puppet", ["master"], @tty) + command_line.legacy_executable_name.should == "puppetmasterd" end it "should leave legacy command names alone" do - Puppet::Util::CommandLine.legacy_executable_name("puppetmasterd", [], @tty).should == "puppetmasterd" - end - - describe "when instantiated" do - it "should provide the results of subcommand and args" do - Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", [], @pipe).returns(["command", ['args']]) - commandline = Puppet::Util::CommandLine.new("puppet", [], @pipe) - - commandline.subcommand_name.should == 'command' - commandline.args.should == ['args'] - end - - it "should provide the legacy executable name" do - Puppet::Util::CommandLine.expects(:subcommand_and_args).with("puppet", ['master'], @pipe).returns(["master", []]) - commandline = Puppet::Util::CommandLine.new("puppet", ['master'], @pipe) - - commandline.legacy_executable_name.should == 'puppetmasterd' - end + command_line = Puppet::Util::CommandLine.new("puppetmasterd", [], @tty) + command_line.legacy_executable_name.should == "puppetmasterd" end end |
