diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-05-29 12:28:51 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-05-29 12:36:10 -0700 |
commit | 86afbbacdfc557bf98ee1d0b7eb0d4b1070e6af2 (patch) | |
tree | 051b3a05233d73e0a565dbde7397d79780189b7c /spec | |
parent | ae85055e3e7d4e0430382839a3e9fc5addb42ee6 (diff) | |
download | chef-86afbbacdfc557bf98ee1d0b7eb0d4b1070e6af2.tar.gz |
Pull in spec task / helper from master
We've changed up some things
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec_helper.rb | 15 | ||||
-rw-r--r-- | spec/support/chef_helpers.rb | 2 | ||||
-rw-r--r-- | spec/unit/data_collector_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/file_access_control_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/json_compat_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource_reporter_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/run_lock_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/scan_access_control_spec.rb | 2 |
8 files changed, 22 insertions, 7 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c9d653adea..01ff1d3c47 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -103,6 +103,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) @@ -282,6 +288,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" diff --git a/spec/support/chef_helpers.rb b/spec/support/chef_helpers.rb index b5d2182d38..461f4ea3de 100644 --- a/spec/support/chef_helpers.rb +++ b/spec/support/chef_helpers.rb @@ -27,7 +27,7 @@ Chef::Log.level(Chef::Config.log_level) Chef::Config.solo(false) def sha256_checksum(path) - OpenSSL::Digest::SHA256.hexdigest(File.read(path)) + OpenSSL::Digest.hexdigest("SHA256", File.read(path)) end # extracted from Ruby < 2.5 to return a unique temp file name without creating it diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index c959776845..6f9b404961 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path("../../spec_helper", __FILE__) +require_relative "../spec_helper" require "chef/data_collector" require "socket" diff --git a/spec/unit/file_access_control_spec.rb b/spec/unit/file_access_control_spec.rb index f1f9cc9ec7..18983e6ff5 100644 --- a/spec/unit/file_access_control_spec.rb +++ b/spec/unit/file_access_control_spec.rb @@ -93,7 +93,7 @@ describe Chef::FileAccessControl do end it "wraps uids to their negative complements to correctly handle negative uids" do - # More: Mac OS X (at least) has negative UIDs for 'nobody' and some other + # More: macOS (at least) has negative UIDs for 'nobody' and some other # users. Ruby doesn't believe in negative UIDs so you get the diminished radix # complement (i.e., it wraps around the maximum size of C unsigned int) of these # uids. So we have to get ruby and negative uids to smoke the peace pipe diff --git a/spec/unit/json_compat_spec.rb b/spec/unit/json_compat_spec.rb index 63c1df93f6..896775f04d 100644 --- a/spec/unit/json_compat_spec.rb +++ b/spec/unit/json_compat_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path("../../spec_helper", __FILE__) +require_relative "../spec_helper" require "chef/json_compat" describe Chef::JSONCompat do diff --git a/spec/unit/resource_reporter_spec.rb b/spec/unit/resource_reporter_spec.rb index db916e824a..6a5b1ef70e 100644 --- a/spec/unit/resource_reporter_spec.rb +++ b/spec/unit/resource_reporter_spec.rb @@ -19,7 +19,7 @@ # limitations under the License. # -require File.expand_path("../../spec_helper", __FILE__) +require_relative "../spec_helper" require "chef/resource_reporter" require "socket" diff --git a/spec/unit/run_lock_spec.rb b/spec/unit/run_lock_spec.rb index 88fa13dfbf..c4fcb8ad6f 100644 --- a/spec/unit/run_lock_spec.rb +++ b/spec/unit/run_lock_spec.rb @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path("../../spec_helper", __FILE__) +require_relative "../spec_helper" require "chef/client" describe Chef::RunLock do diff --git a/spec/unit/scan_access_control_spec.rb b/spec/unit/scan_access_control_spec.rb index 741d5a7748..ba09b990f5 100644 --- a/spec/unit/scan_access_control_spec.rb +++ b/spec/unit/scan_access_control_spec.rb @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path("../../spec_helper", __FILE__) +require_relative "../spec_helper" require "chef/scan_access_control" describe Chef::ScanAccessControl do |