summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-04-09 13:28:17 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2020-04-17 10:20:31 -0700
commitd7452360adb80e383b4886246990dbe46d3387c2 (patch)
tree1d4391bc389a25024fab40ea501745d3e5c8f9dc /spec/spec_helper.rb
parentac47427ab7090453a680c6c4cf6d32eb85cb270d (diff)
downloadchef-d7452360adb80e383b4886246990dbe46d3387c2.tar.gz
Knife bootstrap options cleanup
We have issue that are caused by old code before merging of hash values were done correctly. The `config` hash correctly merges all options and should always be used. Knife plugins should never touch Chef::Config[:knife] values (either reading or writing from them). The `knife_config` should be converted to the `config` hash since it directly accesses Chef::Config[:knife] values. The `config_value()` helper should no longer be used. Very clearly most people started to use that when they should just use the config hash directly. That was intended to be used only when a knife cli option was being renamed and the former configuration value needed to be used as well. It has been cargo culted around as the way to access config values, and that should really stop. The DataBagSecretOption mixin has been cleaned up so that the cli options read+write only to the config[:cl_secret] and config[:cl_secret_file] values. The config file values go into config[:secret] and config[:secret_file]. The fact that those are the merged values in the `config` hash doesn't matter since only the cli should be writing to the first two and only the config file should be writing to the latter two. I don't know why it was made so complicated to begin with, but if there's some hidden chef-11.early backcompat there, then chef-16 deliberately breaks that. The use of `locate_config_value` helpers in all knife plugins is also discouraged (but they all implement those themselves), just use the config hash, which has the correct hash merge ordering. All of those need to be deleted. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 1d85acb4f3..b41e1b3cf3 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -114,6 +114,12 @@ resource_priority_map ||= nil
provider_handler_map ||= nil
resource_handler_map ||= nil
+class UnexpectedSystemExit < RuntimeError
+ def self.from(system_exit)
+ new(system_exit.message).tap { |e| e.set_backtrace(system_exit.backtrace) }
+ end
+end
+
RSpec.configure do |config|
config.include(Matchers)
config.include(MockShellout::RSpec)
@@ -291,6 +297,15 @@ RSpec.configure do |config|
config.before(:suite) do
ARGV.clear
end
+
+ # Protect Rspec from accidental exit(0) causing rspec to terminate without error
+ config.around(:example) do |ex|
+ begin
+ ex.run
+ rescue SystemExit => e
+ raise UnexpectedSystemExit.from(e)
+ end
+ end
end
require "webrick/utils"