diff --git a/Library/Homebrew/.simplecov b/Library/Homebrew/.simplecov
index b2b00acf6671a6ab4a83abe10aff73ef2ec6f022..a18bd3501cba240f42668abf5ff83e04ecefc745 100755
--- a/Library/Homebrew/.simplecov
+++ b/Library/Homebrew/.simplecov
@@ -30,8 +30,6 @@ SimpleCov.start do
     SimpleCov.print_error_status = false
 
     SimpleCov.at_exit do
-      $stdout.reopen("/dev/null")
-
       # Just save result, but don't write formatted output.
       coverage_result = Coverage.result
       # TODO: this method is private, find a better way.
@@ -39,7 +37,10 @@ SimpleCov.start do
       simplecov_result = SimpleCov::Result.new(coverage_result)
       SimpleCov::ResultMerger.store_result(simplecov_result)
 
-      exit! SimpleCov.exit_status_from_exception || 0
+      # If an integration test raises a `SystemExit` exception on exit,
+      # exit immediately using the same status code to avoid reporting
+      # an error when expecting a non-successful exit status.
+      raise if $ERROR_INFO.is_a?(SystemExit)
     end
   else
     command_name "#{command_name} (#{$PROCESS_ID})"
diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
index 9f9e6e576dfeb6abd25067844129440d9af31d70..6a771d1b1c71d83df154b8519e27772d1561b9d9 100644
--- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
+++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb
@@ -13,7 +13,8 @@ RSpec.shared_context "integration test" do
   matcher :be_a_success do
     match do |actual|
       status = actual.is_a?(Proc) ? actual.call : actual
-      status.respond_to?(:success?) && status.success?
+      expect(status).to respond_to(:success?)
+      status.success?
     end
 
     def supports_block_expectations?