diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/application/knife_spec.rb | 17 | ||||
-rw-r--r-- | spec/unit/knife/cookbook_show_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 44 |
3 files changed, 45 insertions, 18 deletions
diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index ea5083ac15..4b727eef93 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -77,6 +77,23 @@ describe Chef::Application::Knife do expect(Chef::Config[:color]).to be_truthy end + context "validate --format option" do + it "should set the default format summary" do + with_argv(*%w{noop knife command}) do + expect(@knife).to receive(:exit).with(0) + @knife.run + expect(@knife.default_config[:format]).to eq("summary") + end + end + + it "should raise the error for invalid value" do + with_argv(*%w{noop knife command -F abc}) do + expect(STDOUT).to receive(:puts).at_least(2).times + expect { @knife.run }.to raise_error(SystemExit) { |e| expect(e.status).to eq(2) } + end + end + end + context "when given fips flags" do context "when Chef::Config[:fips]=false" do before do diff --git a/spec/unit/knife/cookbook_show_spec.rb b/spec/unit/knife/cookbook_show_spec.rb index 6054f8c6b6..b1e7d60e5b 100644 --- a/spec/unit/knife/cookbook_show_spec.rb +++ b/spec/unit/knife/cookbook_show_spec.rb @@ -1,7 +1,7 @@ # # Author:: Adam Jacob (<adam@chef.io>) # Copyright:: Copyright 2008-2017, Chef Software Inc. -# License:: Apache License, eersion 2.0 +# License:: Apache License, version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index 9cefcba84f..ea957ee5f9 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -360,29 +360,39 @@ describe Chef::Knife::Ssh do end describe "#run" do - before do - @query = Chef::Search::Query.new - expect(@query).to receive(:search).and_yield(@node_foo) - allow(Chef::Search::Query).to receive(:new).and_return(@query) - allow(@knife).to receive(:ssh_command).and_return(exit_code) - @knife.name_args = ["*:*", "false"] + + it "should print usage and exit when a SEARCH QUERY is not provided" do + @knife.name_args = [] + expect(@knife).to receive(:show_usage) + expect(@knife.ui).to receive(:fatal).with(/You must specify the SEARCH QUERY./) + expect { @knife.run }.to raise_error(SystemExit) end - context "with an error" do - let(:exit_code) { 1 } + context "exit" do + before do + @query = Chef::Search::Query.new + expect(@query).to receive(:search).and_yield(@node_foo) + allow(Chef::Search::Query).to receive(:new).and_return(@query) + allow(@knife).to receive(:ssh_command).and_return(exit_code) + @knife.name_args = ["*:*", "false"] + end + + context "with an error" do + let(:exit_code) { 1 } - it "should exit with a non-zero exit code" do - expect(@knife).to receive(:exit).with(exit_code) - @knife.run + it "should exit with a non-zero exit code" do + expect(@knife).to receive(:exit).with(exit_code) + @knife.run + end end - end - context "with no error" do - let(:exit_code) { 0 } + context "with no error" do + let(:exit_code) { 0 } - it "should not exit" do - expect(@knife).not_to receive(:exit) - @knife.run + it "should not exit" do + expect(@knife).not_to receive(:exit) + @knife.run + end end end end |