summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2015-09-01 20:59:43 -0700
committerNoah Kantrowitz <noah@coderanger.net>2015-09-01 20:59:43 -0700
commit4c10ab73872c88626392412529abcc3d4e3974bf (patch)
tree7e74f74b3713a7b27b581d9c8af50064b05fdbe0
parent3fa5f5c09f018c08ba64913d82bef6956550fa0b (diff)
downloadchef-4c10ab73872c88626392412529abcc3d4e3974bf.tar.gz
Don't leak log_level=debug out of the cookbook_delete_spec test.
-rw-r--r--spec/functional/knife/cookbook_delete_spec.rb24
1 files changed, 17 insertions, 7 deletions
diff --git a/spec/functional/knife/cookbook_delete_spec.rb b/spec/functional/knife/cookbook_delete_spec.rb
index 15ac8f55ab..bffad8cbed 100644
--- a/spec/functional/knife/cookbook_delete_spec.rb
+++ b/spec/functional/knife/cookbook_delete_spec.rb
@@ -40,20 +40,30 @@ describe Chef::Knife::CookbookDelete do
end
context "when the cookbook doesn't exist" do
- before do
- @log_output = StringIO.new
-
- Chef::Log.logger = Logger.new(@log_output)
- Chef::Log.level = :debug
+ let(:log_output) { StringIO.new }
+ before do
@knife.name_args = %w{no-such-cookbook}
@api.get("/cookbooks/no-such-cookbook", 404, Chef::JSONCompat.to_json({'error'=>'dear Tim, no. -Sent from my iPad'}))
end
+ around do |ex|
+ old_logger = Chef::Log.logger
+ old_level = Chef::Log.level
+ begin
+ Chef::Log.logger = Logger.new(log_output)
+ Chef::Log.level = :debug
+ ex.run
+ ensure
+ Chef::Log.logger = old_logger
+ Chef::Log.level = old_level
+ end
+ end
+
it "logs an error and exits" do
- allow(@knife.ui).to receive(:stderr).and_return(@log_output)
+ allow(@knife.ui).to receive(:stderr).and_return(log_output)
expect {@knife.run}.to raise_error(SystemExit)
- expect(@log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/)
+ expect(log_output.string).to match(/Cannot find a cookbook named no-such-cookbook to delete/)
end
end