diff options
author | Mike Fiedler <miketheman@gmail.com> | 2013-05-24 22:09:33 -0400 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-06-18 10:11:06 -0700 |
commit | 8706908bed44e627303bfcca87a48a2e011335e6 (patch) | |
tree | 2db3b938ed65ca83bbb1bd224ad219d15d0c0c44 | |
parent | b88df4d6991254740c5b04f7a4032b4d8ba32e12 (diff) | |
download | chef-8706908bed44e627303bfcca87a48a2e011335e6.tar.gz |
Adds another test for correct amount of arguments
@fnichol and I paired on this and come to this method.
We split the tests into two cases for test readability.
-rw-r--r-- | lib/chef/knife/node_run_list_set.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/node_run_list_set_spec.rb | 25 |
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/chef/knife/node_run_list_set.rb b/lib/chef/knife/node_run_list_set.rb index 5c7f75ae8b..be37f23273 100644 --- a/lib/chef/knife/node_run_list_set.rb +++ b/lib/chef/knife/node_run_list_set.rb @@ -31,7 +31,11 @@ class Chef def run node = Chef::Node.load(@name_args[0]) - if @name_args.size > 2 + if @name_args.size < 2 + ui.fatal "You must supply both a node name and a run list." + show_usage + exit 1 + elsif @name_args.size > 2 # Check for nested lists and create a single plain one entries = @name_args[1..-1].map do |entry| entry.split(',').map { |e| e.strip } diff --git a/spec/unit/knife/node_run_list_set_spec.rb b/spec/unit/knife/node_run_list_set_spec.rb index 55cfccc90b..bc102695ee 100644 --- a/spec/unit/knife/node_run_list_set_spec.rb +++ b/spec/unit/knife/node_run_list_set_spec.rb @@ -111,5 +111,30 @@ describe Chef::Knife::NodeRunListSet do end end + describe "with no role or recipe" do + # Set up outputs for inspection later + before(:each) do + @stdout = StringIO.new + @stderr = StringIO.new + + @knife.ui.stub!(:stdout).and_return(@stdout) + @knife.ui.stub!(:stderr).and_return(@stderr) + end + + it "should exit" do + @knife.name_args = [ "adam" ] + lambda { @knife.run }.should raise_error SystemExit + end + + it "should show the user" do + @knife.name_args = [ "adam" ] + + begin ; @knife.run ; rescue SystemExit ; end + + @stdout.string.should eq "USAGE: knife node run_list set NODE ENTRIES (options)\n" + @stderr.string.should eq "FATAL: You must supply both a node name and a run list.\n" + end + end + end end |