diff options
author | Bryan McLellan <btm@chef.io> | 2015-11-05 16:28:39 -0500 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-11-06 10:26:48 -0500 |
commit | bd18b913954333f67dc4da4dc3f330298247b3f1 (patch) | |
tree | 0fa4d92638a6f85cdd3256b575ce70f40852d902 /spec/unit/knife_spec.rb | |
parent | 2e09c06915ca8602223d83bf351d439d5c7e9e4f (diff) | |
download | chef-bd18b913954333f67dc4da4dc3f330298247b3f1.tar.gz |
Avoid squashing/humanizing the exception when config[:verbosity] == 2btm/knife-backtrace
We create an instance of Chef::Knife::Bootstrap in knife-ec2, but we've
already processed ARGV so we substitute and process an empty argv.
config[:verbosity] comes from Chef::Application::Knife. Normally we
merge those options with the ones from the knife subcommand in
Chef::Knife.run. Since we don't in this case, we don't set it to the
default of 0 that is specified there, leaving it nil.
We set Chef::Config[:verbosity] to config[:verbosity] in Chef::Knife#initialize
which now becomes nil.
This change makes it so we do not update Chef::Config[:verbosity] if
config[:verbosity] is nil, so that later when we rescue we don't call
humanize_exception if Chef::Config[:verbosity] is 2.
Diffstat (limited to 'spec/unit/knife_spec.rb')
-rw-r--r-- | spec/unit/knife_spec.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index 9ccd91775f..5ab8e84eac 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -63,6 +63,12 @@ describe Chef::Knife do Chef::Knife.reset_config_loader! end + it "does not reset Chef::Config[:verbosity to nil if config[:verbosity] is nil" do + Chef::Config[:verbosity] = 2 + Chef::Knife.new + expect(Chef::Config[:verbosity]).to eq(2) + end + describe "after loading a subcommand" do before do Chef::Knife.reset_subcommands! @@ -309,7 +315,7 @@ describe Chef::Knife do expect(Chef::Config[:listen]).to be(false) end - context "verbosity is greater than zero" do + context "verbosity is one" do let(:fake_config) { "/does/not/exist/knife.rb" } before do @@ -327,6 +333,13 @@ describe Chef::Knife do knife.configure_chef end end + + it "does not humanize the exception if Chef::Config[:verbosity] is two" do + Chef::Config[:verbosity] = 2 + allow(knife).to receive(:run).and_raise(Exception) + expect(knife).not_to receive(:humanize_exception) + expect { knife.run_with_pretty_exceptions }.to raise_error(Exception) + end end end |