summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/spec_helper.rb15
-rw-r--r--spec/support/chef_helpers.rb2
-rw-r--r--spec/unit/data_collector_spec.rb2
-rw-r--r--spec/unit/file_access_control_spec.rb2
-rw-r--r--spec/unit/json_compat_spec.rb2
-rw-r--r--spec/unit/resource_reporter_spec.rb2
-rw-r--r--spec/unit/run_lock_spec.rb2
-rw-r--r--spec/unit/scan_access_control_spec.rb2
-rw-r--r--tasks/rspec.rb18
9 files changed, 27 insertions, 20 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
diff --git a/tasks/rspec.rb b/tasks/rspec.rb
index d7e04767c6..c757d3565d 100644
--- a/tasks/rspec.rb
+++ b/tasks/rspec.rb
@@ -41,39 +41,31 @@ begin
task spec: :component_specs
- desc "Run standard specs (minus long running specs)"
+ desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new(:spec) do |t|
+ t.verbose = false
t.rspec_opts = %w{--profile}
- # right now this just limits to functional + unit, but could also remove
- # individual tests marked long-running
t.pattern = FileList["spec/**/*_spec.rb"]
end
namespace :spec do
- desc "Run all specs in spec directory with RCov"
- RSpec::Core::RakeTask.new(:rcov) do |t|
- t.rspec_opts = %w{--profile}
- t.pattern = FileList["spec/**/*_spec.rb"]
- t.rcov = true
- t.rcov_opts = lambda do
- IO.readlines("#{CHEF_ROOT}/spec/rcov.opts").map { |l| l.chomp.split " " }.flatten
- end
- end
-
desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new(:all) do |t|
+ t.verbose = false
t.rspec_opts = %w{--profile}
t.pattern = FileList["spec/**/*_spec.rb"]
end
desc "Print Specdoc for all specs"
RSpec::Core::RakeTask.new(:doc) do |t|
+ t.verbose = false
t.rspec_opts = %w{--format specdoc --dry-run --profile}
t.pattern = FileList["spec/**/*_spec.rb"]
end
desc "Run the specs under spec/unit with activesupport loaded"
RSpec::Core::RakeTask.new(:activesupport) do |t|
+ t.verbose = false
t.rspec_opts = %w{--require active_support/core_ext --profile}
# Only node_spec and role_spec specifically have issues, target those tests
t.pattern = FileList["spec/unit/node_spec.rb", "spec/unit/role_spec.rb"]