spec/support/knife_support.rb in knife-essentials-0.8.2 vs spec/support/knife_support.rb in knife-essentials-0.8.3

- old
+ new

@@ -1,7 +1,9 @@ require 'chef/knife' require 'chef/application/knife' +require 'logger' +require 'chef/log' module KnifeSupport def knife(*args, &block) # Allow knife('role from file roles/blah.json') rather than requiring the # arguments to be split like knife('role', 'from', 'file', 'roles/blah.json') @@ -14,10 +16,12 @@ # This is Chef::Knife.run without load_commands and load_deps--we'll # load stuff ourselves, thank you very much stdout = StringIO.new stderr = StringIO.new + old_loggers = Chef::Log.loggers + old_log_level = Chef::Log.level begin subcommand_class = Chef::Knife.subcommand_class_from(args) subcommand_class.options = Chef::Application::Knife.options.merge(subcommand_class.options) instance = subcommand_class.new(args) @@ -25,16 +29,24 @@ instance.ui = Chef::Knife::UI.new(stdout, stderr, STDIN, {}) # Don't print stuff Chef::Config[:verbosity] = 0 instance.configure_chef + logger = Logger.new(stderr) + logger.formatter = proc { |severity, datetime, progname, msg| "#{severity}: #{msg}\n" } + Chef::Log.use_log_devices([logger]) + Chef::Log.level = :warn + Chef::Log::Formatter.show_time = false instance.run exit_code = 0 # This is how rspec catches exit() rescue SystemExit => e exit_code = e.status + ensure + Chef::Log.use_log_devices(old_loggers) + Chef::Log.level = old_log_level end KnifeResult.new(stdout.string, stderr.string, exit_code) end