From 622e4406e59a8a5a7f895970375896da6bbf2aee Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Tue, 24 Nov 2026 15:57:21 +0000 Subject: [PATCH 1/2] test(rails): isolate app-booting specs in forked processes --- .../spec/active_job/continuable_spec.rb | 2 +- .../active_job/delayed_job_adapter_spec.rb | 2 +- .../spec/active_job/good_job_cron_spec.rb | 4 +- .../good_job_cron_subscriber_spec.rb | 2 +- sentry-rails/spec/active_job/good_job_spec.rb | 2 +- .../spec/active_job/resque_adapter_spec.rb | 2 +- .../spec/active_job/sidekiq_adapter_spec.rb | 2 +- .../active_job/solid_queue_recurring_spec.rb | 2 +- .../spec/active_job/solid_queue_spec.rb | 2 +- .../spec/active_job/test_adapter_spec.rb | 2 +- .../spec/fixtures/isolation_examples.rb | 55 +++++ sentry-rails/spec/isolation_spec.rb | 118 +++++++++ .../spec/sentry/rails/action_cable_spec.rb | 4 +- .../rails/active_job_hub_isolation_spec.rb | 2 +- .../rails/active_job_job_extensions_spec.rb | 2 +- .../sentry/rails/active_job_ownership_spec.rb | 2 +- .../breadcrumbs/active_support_logger_spec.rb | 2 +- sentry-rails/spec/sentry/rails/client_spec.rb | 2 +- .../spec/sentry/rails/configuration_spec.rb | 2 +- .../sentry/rails/controller_methods_spec.rb | 2 +- sentry-rails/spec/sentry/rails/event_spec.rb | 2 +- .../spec/sentry/rails/log_subscriber_spec.rb | 2 +- .../action_controller_subscriber_spec.rb | 2 +- .../action_mailer_subscriber_spec.rb | 2 +- .../active_job_subscriber_spec.rb | 2 +- .../active_record_subscriber_spec.rb | 2 +- .../sentry/rails/structured_logging_spec.rb | 2 +- .../tracing/action_view_subscriber_spec.rb | 2 +- .../tracing/active_record_subscriber_spec.rb | 2 +- .../tracing/active_storage_subscriber_spec.rb | 2 +- .../tracing/active_support_subscriber_spec.rb | 2 +- .../spec/sentry/rails/tracing_spec.rb | 2 +- sentry-rails/spec/sentry/rails_spec.rb | 2 +- sentry-rails/spec/spec_helper.rb | 2 +- sentry-rails/spec/support/isolation.rb | 233 ++++++++++++++++++ .../spec/versioned/2.7/activejob_spec.rb | 2 +- 36 files changed, 441 insertions(+), 35 deletions(-) create mode 100644 sentry-rails/spec/fixtures/isolation_examples.rb create mode 100644 sentry-rails/spec/isolation_spec.rb create mode 100644 sentry-rails/spec/support/isolation.rb diff --git a/sentry-rails/spec/active_job/continuable_spec.rb b/sentry-rails/spec/active_job/continuable_spec.rb index f52cd37f2..0e4a6e669 100644 --- a/sentry-rails/spec/active_job/continuable_spec.rb +++ b/sentry-rails/spec/active_job/continuable_spec.rb @@ -5,7 +5,7 @@ if RAILS_VERSION >= 8.1 require "active_job/continuation/test_helper" - RSpec.describe "Sentry + ActiveJob::Continuable", type: :job do + RSpec.describe "Sentry + ActiveJob::Continuable", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :test include_context "test adapter" include ActiveJob::Continuation::TestHelper diff --git a/sentry-rails/spec/active_job/delayed_job_adapter_spec.rb b/sentry-rails/spec/active_job/delayed_job_adapter_spec.rb index a807c48ea..9d3b685ee 100644 --- a/sentry-rails/spec/active_job/delayed_job_adapter_spec.rb +++ b/sentry-rails/spec/active_job/delayed_job_adapter_spec.rb @@ -20,7 +20,7 @@ return end -RSpec.describe "Sentry + ActiveJob on the delayed_job adapter", type: :job do +RSpec.describe "Sentry + ActiveJob on the delayed_job adapter", type: :job, isolate: :group do include ActiveSupport::Testing::TimeHelpers include_context "active_job backend harness", adapter: :delayed_job include_context "delayed_job adapter" diff --git a/sentry-rails/spec/active_job/good_job_cron_spec.rb b/sentry-rails/spec/active_job/good_job_cron_spec.rb index 746e4729b..4f0d997b6 100644 --- a/sentry-rails/spec/active_job/good_job_cron_spec.rb +++ b/sentry-rails/spec/active_job/good_job_cron_spec.rb @@ -8,7 +8,7 @@ end if defined?(::GoodJob) - RSpec.describe Sentry::Rails::GoodJobCron, type: :job do + RSpec.describe Sentry::Rails::GoodJobCron, type: :job, isolate: :group do before(:all) do skip "GoodJob cron specs run the real GoodJob adapter, which ActiveJob::TestHelper supports from Rails 7.1" if RAILS_VERSION < 7.1 end @@ -458,7 +458,7 @@ def perform; end end if RAILS_VERSION >= 7.1 - RSpec.describe "Sentry::Rails::GoodJobCron on a GoodJob database", type: :job do + RSpec.describe "Sentry::Rails::GoodJobCron on a GoodJob database", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :good_job include_context "good_job database" diff --git a/sentry-rails/spec/active_job/good_job_cron_subscriber_spec.rb b/sentry-rails/spec/active_job/good_job_cron_subscriber_spec.rb index 99a643d78..3df36ae25 100644 --- a/sentry-rails/spec/active_job/good_job_cron_subscriber_spec.rb +++ b/sentry-rails/spec/active_job/good_job_cron_subscriber_spec.rb @@ -8,7 +8,7 @@ end if defined?(::GoodJob) - RSpec.describe "GoodJob cron notification subscriber", type: :job do + RSpec.describe "GoodJob cron notification subscriber", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :test include_context "test adapter" diff --git a/sentry-rails/spec/active_job/good_job_spec.rb b/sentry-rails/spec/active_job/good_job_spec.rb index e4c8889f2..b8eebc807 100644 --- a/sentry-rails/spec/active_job/good_job_spec.rb +++ b/sentry-rails/spec/active_job/good_job_spec.rb @@ -12,7 +12,7 @@ GOOD_JOB_ADAPTER_FOR_TEST = ::ActiveJob::QueueAdapters::GoodJobAdapter.new(execution_mode: :external) -RSpec.describe "Sentry + ActiveJob on GoodJob", type: :job do +RSpec.describe "Sentry + ActiveJob on GoodJob", type: :job, isolate: :group do include ActiveSupport::Testing::TimeHelpers include_context "active_job backend harness", adapter: :good_job include_context "good_job database" diff --git a/sentry-rails/spec/active_job/resque_adapter_spec.rb b/sentry-rails/spec/active_job/resque_adapter_spec.rb index cc9b8ffe0..d203ad603 100644 --- a/sentry-rails/spec/active_job/resque_adapter_spec.rb +++ b/sentry-rails/spec/active_job/resque_adapter_spec.rb @@ -21,7 +21,7 @@ return end -RSpec.describe "Sentry + ActiveJob on the resque adapter", type: :job do +RSpec.describe "Sentry + ActiveJob on the resque adapter", type: :job, isolate: :group do include ActiveSupport::Testing::TimeHelpers include_context "active_job backend harness", adapter: :resque include_context "resque adapter" diff --git a/sentry-rails/spec/active_job/sidekiq_adapter_spec.rb b/sentry-rails/spec/active_job/sidekiq_adapter_spec.rb index be7b15fd7..964ab554e 100644 --- a/sentry-rails/spec/active_job/sidekiq_adapter_spec.rb +++ b/sentry-rails/spec/active_job/sidekiq_adapter_spec.rb @@ -23,7 +23,7 @@ return end -RSpec.describe "Sentry + ActiveJob on the sidekiq adapter", type: :job do +RSpec.describe "Sentry + ActiveJob on the sidekiq adapter", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :sidekiq include_context "sidekiq adapter" diff --git a/sentry-rails/spec/active_job/solid_queue_recurring_spec.rb b/sentry-rails/spec/active_job/solid_queue_recurring_spec.rb index 30aedb04c..9bc98790a 100644 --- a/sentry-rails/spec/active_job/solid_queue_recurring_spec.rb +++ b/sentry-rails/spec/active_job/solid_queue_recurring_spec.rb @@ -7,7 +7,7 @@ SOLID_QUEUE_RECURRING_ADAPTER = ::ActiveJob::QueueAdapters::SolidQueueAdapter.new - RSpec.describe Sentry::Rails::SolidQueueRecurring, type: :job do + RSpec.describe Sentry::Rails::SolidQueueRecurring, type: :job, isolate: :group do include_context "active_job backend harness", adapter: :solid_queue let(:excluded_tasks) { [] } diff --git a/sentry-rails/spec/active_job/solid_queue_spec.rb b/sentry-rails/spec/active_job/solid_queue_spec.rb index 6d511b367..91210fc3c 100644 --- a/sentry-rails/spec/active_job/solid_queue_spec.rb +++ b/sentry-rails/spec/active_job/solid_queue_spec.rb @@ -5,7 +5,7 @@ if RAILS_VERSION >= 7.1 && RUBY_VERSION >= "3.1" require "solid_queue" - RSpec.describe "Sentry + ActiveJob on SolidQueue", type: :job do + RSpec.describe "Sentry + ActiveJob on SolidQueue", type: :job, isolate: :group do include ActiveSupport::Testing::TimeHelpers include_context "active_job backend harness", adapter: :solid_queue diff --git a/sentry-rails/spec/active_job/test_adapter_spec.rb b/sentry-rails/spec/active_job/test_adapter_spec.rb index d968699d6..c2cbe7add 100644 --- a/sentry-rails/spec/active_job/test_adapter_spec.rb +++ b/sentry-rails/spec/active_job/test_adapter_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "Sentry + ActiveJob on the test adapter", type: :job do +RSpec.describe "Sentry + ActiveJob on the test adapter", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :test include_context "test adapter" diff --git a/sentry-rails/spec/fixtures/isolation_examples.rb b/sentry-rails/spec/fixtures/isolation_examples.rb new file mode 100644 index 000000000..641b8958c --- /dev/null +++ b/sentry-rails/spec/fixtures/isolation_examples.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +# Run by spec/isolation_spec.rb in a separate rspec process. Not part of the suite. +require "spec_helper" + +RUNNER_PID = Process.pid + +RSpec.describe "isolated examples", isolate: true do + it("fails an expectation") { expect(1).to eq(2) } + it("raises an error") { raise ArgumentError, "boom" } + it("dies without reporting") { exit!(3) } + it("skips") { skip "not today" } + it("passes") { expect(Process.pid).not_to eq(RUNNER_PID) } + + context "with a failing hook" do + before { raise "hook failed" } + + it("reports the hook error") { } + end +end + +RSpec.describe "not isolated" do + it("runs in the parent process") { expect(Process.pid).to eq(RUNNER_PID) } +end + +RSpec.describe "per-example isolation reports several errors" do + context "with a failing body and a failing after hook", isolate: true do + after { raise "after hook failed" } + + it("reports both errors") { raise "body failed" } + end +end + +RSpec.describe "group isolation", isolate: :group do + before(:all) { @booted_in = Process.pid } + + it("runs the group in a child process") { expect(@booted_in).not_to eq(RUNNER_PID) } + + it("shares before(:all) state across examples") do + $group_runs = ($group_runs || 0) + 1 + expect(@booted_in).to eq(Process.pid) + end + + it("keeps state from earlier examples of the group") { expect($group_runs).to eq(1) } + + it("sets state that must not leak") { $group_leak = :leaked } + + it("fails inside the group") { expect(:a).to eq(:b) } + + it("skips inside the group") { skip "group skip" } +end + +RSpec.describe "after a group-isolated group" do + it("sees no state from the group") { expect($group_leak).to be_nil } +end diff --git a/sentry-rails/spec/isolation_spec.rb b/sentry-rails/spec/isolation_spec.rb new file mode 100644 index 000000000..176c1173c --- /dev/null +++ b/sentry-rails/spec/isolation_spec.rb @@ -0,0 +1,118 @@ +# frozen_string_literal: true + +require "spec_helper" +require "json" +require "tmpdir" + +RSpec.describe "isolate: true metadata" do + PARENT_PID = Process.pid + + context "when examples are tagged", order: :defined do + it "runs in a child process", isolate: true do + expect(Process.pid).not_to eq(PARENT_PID) + end + + it "keeps global state changed by the example out of the parent", isolate: true do + $isolation_leak = :leaked + end + + it "does not see state changed by an isolated example" do + expect($isolation_leak).to be_nil + end + end + + context "when reporting results to RSpec" do + before(:context) do + Dir.mktmpdir do |dir| + out = File.join(dir, "report.json") + @coverage_dir = File.join(dir, "coverage") + system( + { "SENTRY_RAILS_COVERAGE_DIR" => @coverage_dir }, + "bundle", "exec", "rspec", File.join(__dir__, "fixtures/isolation_examples.rb"), + "--format", "json", "--out", out, "--no-color", + out: File::NULL, err: File::NULL + ) + @report = JSON.parse(File.read(out)) + resultset = File.join(@coverage_dir, ".resultset.json") + @coverage_runs = File.exist?(resultset) ? JSON.parse(File.read(resultset)).keys : [] + end + end + + def example_named(description) + @report.fetch("examples").find { |e| e["description"] == description } or raise "no example #{description}" + end + + it "passes isolated examples that pass and leaves untagged examples in the runner" do + expect(example_named("passes")["status"]).to eq("passed") + expect(example_named("runs in the parent process")["status"]).to eq("passed") + end + + it "reports an expectation failure with its message" do + example = example_named("fails an expectation") + + expect(example["status"]).to eq("failed") + expect(example.dig("exception", "class")).to eq("RSpec::Expectations::ExpectationNotMetError") + expect(example.dig("exception", "message")).to include("expected: 2", "got: 1") + end + + it "reports an unexpected error with its class, message and backtrace" do + example = example_named("raises an error") + + expect(example["status"]).to eq("failed") + expect(example["exception"]).to include("class" => "ArgumentError", "message" => "boom") + expect(example.dig("exception", "backtrace")).not_to be_empty + end + + it "reports errors raised in hooks" do + example = example_named("reports the hook error") + + expect(example["status"]).to eq("failed") + expect(example.dig("exception", "message")).to eq("hook failed") + end + + it "reports a child that dies without reporting" do + example = example_named("dies without reporting") + + expect(example["status"]).to eq("failed") + expect(example.dig("exception", "message")).to match(/exited without reporting.*exit 3/) + end + + it "records coverage from the child process" do + expect(@coverage_runs).to include(a_string_matching(/subprocess/)) + end + +it "reports every error of an example that fails more than once" do + example = example_named("reports both errors") + + expect(example["status"]).to eq("failed") + expect(example.dig("exception", "message")).to include("body failed", "after hook failed") +end + +it "runs a group-isolated group in a child process with shared before(:all) state" do + expect(example_named("runs the group in a child process")["status"]).to eq("passed") + expect(example_named("shares before(:all) state across examples")["status"]).to eq("passed") + expect(example_named("keeps state from earlier examples of the group")["status"]).to eq("passed") +end + +it "keeps state from a group-isolated group out of the runner" do + expect(example_named("sees no state from the group")["status"]).to eq("passed") +end + +it "reports failures and skips inside a group-isolated group" do + failed = example_named("fails inside the group") + skipped = example_named("skips inside the group") + + expect(failed["status"]).to eq("failed") + expect(failed.dig("exception", "message")).to include("expected: :b", "got: :a") + expect(skipped["status"]).to eq("pending") + expect(skipped["pending_message"]).to eq("group skip") +end + + it "keeps skipped examples skipped with their reason" do + example = example_named("skips") + + expect(example["status"]).to eq("pending") + expect(example["pending_message"]).to eq("not today") + end + end +end diff --git a/sentry-rails/spec/sentry/rails/action_cable_spec.rb b/sentry-rails/spec/sentry/rails/action_cable_spec.rb index e47ad2efa..b13a4317f 100644 --- a/sentry-rails/spec/sentry/rails/action_cable_spec.rb +++ b/sentry-rails/spec/sentry/rails/action_cable_spec.rb @@ -40,7 +40,7 @@ def disconnect end end - RSpec.describe "without Sentry initialized" do + RSpec.describe "without Sentry initialized", isolate: true do before do allow(Sentry).to receive(:get_main_hub).and_return(nil) make_basic_app @@ -66,7 +66,7 @@ def disconnect end end - RSpec.describe "Sentry::Rails::ActionCableExtensions", type: :channel do + RSpec.describe "Sentry::Rails::ActionCableExtensions", type: :channel, isolate: true do let(:transport) { Sentry.get_current_client.transport } after do diff --git a/sentry-rails/spec/sentry/rails/active_job_hub_isolation_spec.rb b/sentry-rails/spec/sentry/rails/active_job_hub_isolation_spec.rb index 0f1bcf7e8..6c1651d8b 100644 --- a/sentry-rails/spec/sentry/rails/active_job_hub_isolation_spec.rb +++ b/sentry-rails/spec/sentry/rails/active_job_hub_isolation_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "ActiveJob hub isolation through the Rails request stack", type: :request do +RSpec.describe "ActiveJob hub isolation through the Rails request stack", type: :request, isolate: true do let(:transport) { Sentry.get_current_client.transport } before do diff --git a/sentry-rails/spec/sentry/rails/active_job_job_extensions_spec.rb b/sentry-rails/spec/sentry/rails/active_job_job_extensions_spec.rb index 3354eeca1..39c6a1ff6 100644 --- a/sentry-rails/spec/sentry/rails/active_job_job_extensions_spec.rb +++ b/sentry-rails/spec/sentry/rails/active_job_job_extensions_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "Sentry + ActiveJob with a registered job extension", type: :job do +RSpec.describe "Sentry + ActiveJob with a registered job extension", type: :job, isolate: :group do include_context "active_job backend harness", adapter: :test include_context "test adapter" diff --git a/sentry-rails/spec/sentry/rails/active_job_ownership_spec.rb b/sentry-rails/spec/sentry/rails/active_job_ownership_spec.rb index 3cc14c575..56bdf708c 100644 --- a/sentry-rails/spec/sentry/rails/active_job_ownership_spec.rb +++ b/sentry-rails/spec/sentry/rails/active_job_ownership_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "Sentry::Rails.active_job_owns_adapter?" do +RSpec.describe "Sentry::Rails.active_job_owns_adapter?", isolate: true do let(:adapter_class_name) { "ActiveJob::QueueAdapters::SidekiqAdapter" } it "is true when Sentry is initialized and the adapter is not skipped" do diff --git a/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb b/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb index c7ad9eddc..6d41e1818 100644 --- a/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb +++ b/sentry-rails/spec/sentry/rails/breadcrumbs/active_support_logger_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe "Sentry::Breadcrumbs::ActiveSupportLogger", type: :request do +RSpec.describe "Sentry::Breadcrumbs::ActiveSupportLogger", type: :request, isolate: true do after do Sentry::Rails::Breadcrumb::ActiveSupportLogger.detach # even though we cleanup breadcrumbs in the rack middleware diff --git a/sentry-rails/spec/sentry/rails/client_spec.rb b/sentry-rails/spec/sentry/rails/client_spec.rb index aff8a1a62..b14d853d5 100644 --- a/sentry-rails/spec/sentry/rails/client_spec.rb +++ b/sentry-rails/spec/sentry/rails/client_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Client, type: :request, retry: 3, skip: Gem::Version.new(Rails.version) < Gem::Version.new('5.1.0') do +RSpec.describe Sentry::Client, type: :request, retry: 3, skip: Gem::Version.new(Rails.version) < Gem::Version.new('5.1.0'), isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails/configuration_spec.rb b/sentry-rails/spec/sentry/rails/configuration_spec.rb index f1d58a656..8a60e50fd 100644 --- a/sentry-rails/spec/sentry/rails/configuration_spec.rb +++ b/sentry-rails/spec/sentry/rails/configuration_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Configuration do +RSpec.describe Sentry::Rails::Configuration, isolate: true do it "adds #rails option to Sentry::Configuration" do config = Sentry::Configuration.new diff --git a/sentry-rails/spec/sentry/rails/controller_methods_spec.rb b/sentry-rails/spec/sentry/rails/controller_methods_spec.rb index 0f9c82af6..2009e1cee 100644 --- a/sentry-rails/spec/sentry/rails/controller_methods_spec.rb +++ b/sentry-rails/spec/sentry/rails/controller_methods_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require "sentry/rails/controller_methods" -RSpec.describe Sentry::Rails::ControllerMethods do +RSpec.describe Sentry::Rails::ControllerMethods, isolate: true do include described_class def request diff --git a/sentry-rails/spec/sentry/rails/event_spec.rb b/sentry-rails/spec/sentry/rails/event_spec.rb index 92db6f0c3..2c6647d29 100644 --- a/sentry-rails/spec/sentry/rails/event_spec.rb +++ b/sentry-rails/spec/sentry/rails/event_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Sentry::Event do +RSpec.describe Sentry::Event, isolate: true do before do make_basic_app end diff --git a/sentry-rails/spec/sentry/rails/log_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/log_subscriber_spec.rb index 3f8ab3af1..6e70116e1 100644 --- a/sentry-rails/spec/sentry/rails/log_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/log_subscriber_spec.rb @@ -4,7 +4,7 @@ require "sentry/rails/log_subscriber" -RSpec.describe Sentry::Rails::LogSubscriber, type: :request do +RSpec.describe Sentry::Rails::LogSubscriber, type: :request, isolate: true do let!(:test_subscriber) { test_subscriber_class.new } after do diff --git a/sentry-rails/spec/sentry/rails/log_subscribers/action_controller_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/log_subscribers/action_controller_subscriber_spec.rb index 029a5c09f..b86d36d02 100644 --- a/sentry-rails/spec/sentry/rails/log_subscribers/action_controller_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/log_subscribers/action_controller_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::LogSubscribers::ActionControllerSubscriber, type: :request do +RSpec.describe Sentry::Rails::LogSubscribers::ActionControllerSubscriber, type: :request, isolate: true do context "when logging is enabled" do let(:send_default_pii) { false } diff --git a/sentry-rails/spec/sentry/rails/log_subscribers/action_mailer_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/log_subscribers/action_mailer_subscriber_spec.rb index 6cfc8ea34..d198ece92 100644 --- a/sentry-rails/spec/sentry/rails/log_subscribers/action_mailer_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/log_subscribers/action_mailer_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::LogSubscribers::ActionMailerSubscriber do +RSpec.describe Sentry::Rails::LogSubscribers::ActionMailerSubscriber, isolate: true do context "when logging is enabled" do let(:send_default_pii) { false } diff --git a/sentry-rails/spec/sentry/rails/log_subscribers/active_job_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/log_subscribers/active_job_subscriber_spec.rb index 58dda3d4e..94a26c48b 100644 --- a/sentry-rails/spec/sentry/rails/log_subscribers/active_job_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/log_subscribers/active_job_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::LogSubscribers::ActiveJobSubscriber, skip: Rails.version.to_f < 5.1 do +RSpec.describe Sentry::Rails::LogSubscribers::ActiveJobSubscriber, skip: Rails.version.to_f < 5.1, isolate: true do context "when logging is enabled" do let(:send_default_pii) { false } diff --git a/sentry-rails/spec/sentry/rails/log_subscribers/active_record_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/log_subscribers/active_record_subscriber_spec.rb index 3e9f108db..ebea16f3f 100644 --- a/sentry-rails/spec/sentry/rails/log_subscribers/active_record_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/log_subscribers/active_record_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::LogSubscribers::ActiveRecordSubscriber do +RSpec.describe Sentry::Rails::LogSubscribers::ActiveRecordSubscriber, isolate: true do context "when logging is enabled" do let(:send_default_pii) { false } diff --git a/sentry-rails/spec/sentry/rails/structured_logging_spec.rb b/sentry-rails/spec/sentry/rails/structured_logging_spec.rb index 4d9ad9894..11626be32 100644 --- a/sentry-rails/spec/sentry/rails/structured_logging_spec.rb +++ b/sentry-rails/spec/sentry/rails/structured_logging_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::StructuredLogging, type: :request do +RSpec.describe Sentry::Rails::StructuredLogging, type: :request, isolate: true do context "when rails structured logging is disabled" do before do make_basic_app do |config| diff --git a/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb index b847089b6..cc88c8fae 100644 --- a/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/action_view_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Tracing::ActionViewSubscriber, :subscriber, type: :request do +RSpec.describe Sentry::Rails::Tracing::ActionViewSubscriber, :subscriber, type: :request, isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb index 45b80d321..71496f43e 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Tracing::ActiveRecordSubscriber, :subscriber do +RSpec.describe Sentry::Rails::Tracing::ActiveRecordSubscriber, :subscriber, isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb index e77d041fa..428b6b7dd 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_storage_subscriber_spec.rb @@ -4,7 +4,7 @@ # Skipped on JRuby because it's very flaky there due to shelling out to use imagemagick CLI RSpec.describe Sentry::Rails::Tracing::ActiveStorageSubscriber, :subscriber, type: :request, - skip: Rails.version.to_f <= 5.2 || RUBY_PLATFORM == "java" do + skip: Rails.version.to_f <= 5.2 || RUBY_PLATFORM == "java", isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb b/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb index 0efaa33d5..3487bbfa8 100644 --- a/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing/active_support_subscriber_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Tracing::ActiveSupportSubscriber, :subscriber, type: :request do +RSpec.describe Sentry::Rails::Tracing::ActiveSupportSubscriber, :subscriber, type: :request, isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails/tracing_spec.rb b/sentry-rails/spec/sentry/rails/tracing_spec.rb index 55028ea0d..cd3102916 100644 --- a/sentry-rails/spec/sentry/rails/tracing_spec.rb +++ b/sentry-rails/spec/sentry/rails/tracing_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails::Tracing, type: :request do +RSpec.describe Sentry::Rails::Tracing, type: :request, isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/sentry/rails_spec.rb b/sentry-rails/spec/sentry/rails_spec.rb index a3ca2dcae..35e9aebef 100644 --- a/sentry-rails/spec/sentry/rails_spec.rb +++ b/sentry-rails/spec/sentry/rails_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -RSpec.describe Sentry::Rails, type: :request do +RSpec.describe Sentry::Rails, type: :request, isolate: true do let(:transport) do Sentry.get_current_client.transport end diff --git a/sentry-rails/spec/spec_helper.rb b/sentry-rails/spec/spec_helper.rb index cde34bdbd..e0ab55400 100644 --- a/sentry-rails/spec/spec_helper.rb +++ b/sentry-rails/spec/spec_helper.rb @@ -18,7 +18,7 @@ SimpleCov.start do project_name "sentry-rails" root File.join(__FILE__, "../../../") - coverage_dir File.join(__FILE__, "../../coverage") + coverage_dir ENV.fetch("SENTRY_RAILS_COVERAGE_DIR") { File.join(__FILE__, "../../coverage") } end diff --git a/sentry-rails/spec/support/isolation.rb b/sentry-rails/spec/support/isolation.rb new file mode 100644 index 000000000..4ff923431 --- /dev/null +++ b/sentry-rails/spec/support/isolation.rb @@ -0,0 +1,233 @@ +# frozen_string_literal: true + +# Runs specs in a forked child process, so the process-global state a Rails app +# boot leaves behind (load hooks, callbacks, singletons) dies with the child +# instead of leaking into later examples. +# +# it "boots its own app", isolate: true do # one process per example +# make_basic_app { |config| config.traces_sample_rate = 1.0 } +# end +# +# RSpec.describe "boots once", isolate: :group do # one process per group +# before(:all) { make_basic_app } +# end +# +# Both forms also work on a context or describe block. The whole lifecycle +# (hooks, `let`s, bodies) runs in the child, so the parent never touches the +# app. The child sends back plain data and the parent records it on the real +# examples, so formatters, retries and the exit status behave as usual. +# +# Without `fork` (JRuby, Windows) tagged specs run in-process instead. +# +# This hooks into RSpec::Core::Example#run, RSpec::Core::ExampleGroup.run and +# the private Example#start/finish/set_exception, because an `around` hook +# can't skip the example body in the parent. The specs in spec/isolation_spec.rb +# guard that seam across RSpec upgrades. +module Test + module Isolation + TIMEOUT = 120 + + ChildCrashed = Class.new(StandardError) + + # Stands in for RSpec's reporter inside a group-isolated child and keeps + # what the parent needs to replay. + class Recorder + attr_reader :examples, :non_example_errors + + def initialize + @examples = [] + @non_example_errors = [] + end + + def example_finished(example) + @examples << [example.id, Isolation.summarize(example)] + end + + def notify_non_example_exception(error, context) + @non_example_errors << { error: Isolation.serialize_error(error), context: context } + end + + def fail_fast_limit_met? + false + end + + def method_missing(*) + nil + end + + def respond_to_missing?(*) + true + end + end + + module ExampleExtension + def run(example_group_instance, reporter) + return super unless metadata[:isolate] == true && Isolation.forking? + + summary = Isolation.run_in_child do + super(example_group_instance, RSpec::Core::NullReporter) + Isolation.summarize(self) + end + Isolation.replay(self, summary, reporter) + end + end + + module GroupExtension + def run(reporter = RSpec::Core::NullReporter) + return super unless Isolation.isolate_group?(self) + + result = Isolation.run_in_child do + recorder = Recorder.new + super(recorder) + { examples: recorder.examples, errors: recorder.non_example_errors } + end + + Isolation.replay_group(self, result, reporter) + end + end + + class << self + def forking? + Process.respond_to?(:fork) && !@in_child + end + + def isolate_group?(group) + return false unless forking? && group.metadata[:isolate] == :group + + parent = group.superclass + !(parent.respond_to?(:metadata) && parent.metadata && parent.metadata[:isolate] == :group) + end + + def run_in_child + reader, writer = IO.pipe + reader.binmode + writer.binmode + + pid = fork do + @in_child = true + reader.close + Coverage.start_in_child + data = Marshal.dump(yield) + writer.write(data) + writer.close + Coverage.save_from_child + $stdout.flush + $stderr.flush + exit!(0) + end + + writer.close + wait_for_result(reader, pid) + ensure + reader&.close + writer&.close + end + + def summarize(example) + result = example.execution_result + summary = { status: result.status, message: result.pending_message } + summary[:error] = serialize_error(example.exception) if example.exception + summary + end + + def serialize_error(error) + serialized = { class: error.class.name, message: error.message, backtrace: error.backtrace } + serialized[:all] = error.all_exceptions.map { |e| serialize_error(e) } if error.respond_to?(:all_exceptions) + serialized + end + + def replay(example, summary, reporter) + RSpec.current_example = example + example.send(:start, reporter) + + case summary[:status] + when :failed + example.send(:set_exception, rebuild_error(summary[:error])) + when :pending + RSpec::Core::Pending.mark_pending!(example, summary[:message]) + end + + example.send(:finish, reporter) + ensure + example.execution_result.ensure_timing_set(RSpec::Core::Time) + RSpec.current_example = nil + end + + def replay_group(group, result, reporter) + reporter.example_group_started(group) + + by_id = group.descendants.flat_map(&:examples).to_h { |example| [example.id, example] } + recorded = result.fetch(:examples, []).to_h + crash = result[:crash] + + by_id.each do |id, example| + summary = recorded[id] || (crash && { status: :failed, error: crash }) + replay(example, summary, reporter) if summary + end + + result.fetch(:errors, []).each do |entry| + reporter.notify_non_example_exception(rebuild_error(entry[:error]), entry[:context]) + end + + recorded.values.none? { |s| s[:status] == :failed } && !crash + ensure + reporter.example_group_finished(group) + end + + def wait_for_result(reader, pid) + if IO.select([reader], nil, nil, TIMEOUT) + data = reader.read + status = Process.wait2(pid).last + return Marshal.load(data) unless data.empty? + + crashed("isolated spec exited without reporting (#{status.inspect})") + else + Process.kill("KILL", pid) + Process.wait(pid) + crashed("isolated spec timed out after #{TIMEOUT}s") + end + end + + def crashed(message) + error = { class: ChildCrashed.name, message: message, backtrace: [] } + { status: :failed, error: error, crash: error, examples: [] } + end + + def rebuild_error(error) + return RSpec::Core::MultipleExceptionError.new(*error[:all].map { |e| rebuild_error(e) }) if error[:all] + + klass = Object.const_get(error[:class]) if error[:class] + exception = klass.is_a?(Class) && klass <= Exception ? klass.new(error[:message]) : ChildCrashed.new("#{error[:class]}: #{error[:message]}") + exception.set_backtrace(error[:backtrace] || []) + exception + rescue NameError, ArgumentError, TypeError + ChildCrashed.new("#{error[:class]}: #{error[:message]}").tap { |e| e.set_backtrace(error[:backtrace] || []) } + end + end + + # The child exits with `exit!`, which skips SimpleCov's at_exit hook, so it + # starts its own measurement (the same thing SimpleCov's subprocess support + # does) and stores its result for the parent to merge at exit. + module Coverage + module_function + + def start_in_child + return unless simplecov_running? + + ::Coverage.result(stop: false, clear: true) + SimpleCov.at_fork.call(Process.pid) + end + + def save_from_child + SimpleCov.result if simplecov_running? + end + + def simplecov_running? + defined?(::SimpleCov) && ::SimpleCov.running + end + end + end +end + +RSpec::Core::Example.prepend(Test::Isolation::ExampleExtension) +RSpec::Core::ExampleGroup.singleton_class.prepend(Test::Isolation::GroupExtension) diff --git a/sentry-rails/spec/versioned/2.7/activejob_spec.rb b/sentry-rails/spec/versioned/2.7/activejob_spec.rb index ab905a5fb..13016ef20 100644 --- a/sentry-rails/spec/versioned/2.7/activejob_spec.rb +++ b/sentry-rails/spec/versioned/2.7/activejob_spec.rb @@ -5,7 +5,7 @@ # isolated tests need a SimpleCov name otherwise they will overwrite coverage SimpleCov.command_name "RSpecVersioned_2.7_ActiveJob" -RSpec.describe "ActiveJob integration", type: :job do +RSpec.describe "ActiveJob integration", type: :job, isolate: true do before do make_basic_app do |config| config.data_collection.queues = true From ff246d533dd22b6eb4e673e8e216528fcfa4d2aa Mon Sep 17 00:00:00 2001 From: Peter Solnica Date: Tue, 24 Nov 2026 17:57:43 +0000 Subject: [PATCH 2/2] test(rails): aggregate forked spec coverage once in the parent --- .../spec/fixtures/isolation_examples.rb | 55 -------- sentry-rails/spec/isolation_spec.rb | 118 ------------------ sentry-rails/spec/spec_helper.rb | 2 +- sentry-rails/spec/support/isolation.rb | 43 +++++-- 4 files changed, 31 insertions(+), 187 deletions(-) delete mode 100644 sentry-rails/spec/fixtures/isolation_examples.rb delete mode 100644 sentry-rails/spec/isolation_spec.rb diff --git a/sentry-rails/spec/fixtures/isolation_examples.rb b/sentry-rails/spec/fixtures/isolation_examples.rb deleted file mode 100644 index 641b8958c..000000000 --- a/sentry-rails/spec/fixtures/isolation_examples.rb +++ /dev/null @@ -1,55 +0,0 @@ -# frozen_string_literal: true - -# Run by spec/isolation_spec.rb in a separate rspec process. Not part of the suite. -require "spec_helper" - -RUNNER_PID = Process.pid - -RSpec.describe "isolated examples", isolate: true do - it("fails an expectation") { expect(1).to eq(2) } - it("raises an error") { raise ArgumentError, "boom" } - it("dies without reporting") { exit!(3) } - it("skips") { skip "not today" } - it("passes") { expect(Process.pid).not_to eq(RUNNER_PID) } - - context "with a failing hook" do - before { raise "hook failed" } - - it("reports the hook error") { } - end -end - -RSpec.describe "not isolated" do - it("runs in the parent process") { expect(Process.pid).to eq(RUNNER_PID) } -end - -RSpec.describe "per-example isolation reports several errors" do - context "with a failing body and a failing after hook", isolate: true do - after { raise "after hook failed" } - - it("reports both errors") { raise "body failed" } - end -end - -RSpec.describe "group isolation", isolate: :group do - before(:all) { @booted_in = Process.pid } - - it("runs the group in a child process") { expect(@booted_in).not_to eq(RUNNER_PID) } - - it("shares before(:all) state across examples") do - $group_runs = ($group_runs || 0) + 1 - expect(@booted_in).to eq(Process.pid) - end - - it("keeps state from earlier examples of the group") { expect($group_runs).to eq(1) } - - it("sets state that must not leak") { $group_leak = :leaked } - - it("fails inside the group") { expect(:a).to eq(:b) } - - it("skips inside the group") { skip "group skip" } -end - -RSpec.describe "after a group-isolated group" do - it("sees no state from the group") { expect($group_leak).to be_nil } -end diff --git a/sentry-rails/spec/isolation_spec.rb b/sentry-rails/spec/isolation_spec.rb deleted file mode 100644 index 176c1173c..000000000 --- a/sentry-rails/spec/isolation_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true - -require "spec_helper" -require "json" -require "tmpdir" - -RSpec.describe "isolate: true metadata" do - PARENT_PID = Process.pid - - context "when examples are tagged", order: :defined do - it "runs in a child process", isolate: true do - expect(Process.pid).not_to eq(PARENT_PID) - end - - it "keeps global state changed by the example out of the parent", isolate: true do - $isolation_leak = :leaked - end - - it "does not see state changed by an isolated example" do - expect($isolation_leak).to be_nil - end - end - - context "when reporting results to RSpec" do - before(:context) do - Dir.mktmpdir do |dir| - out = File.join(dir, "report.json") - @coverage_dir = File.join(dir, "coverage") - system( - { "SENTRY_RAILS_COVERAGE_DIR" => @coverage_dir }, - "bundle", "exec", "rspec", File.join(__dir__, "fixtures/isolation_examples.rb"), - "--format", "json", "--out", out, "--no-color", - out: File::NULL, err: File::NULL - ) - @report = JSON.parse(File.read(out)) - resultset = File.join(@coverage_dir, ".resultset.json") - @coverage_runs = File.exist?(resultset) ? JSON.parse(File.read(resultset)).keys : [] - end - end - - def example_named(description) - @report.fetch("examples").find { |e| e["description"] == description } or raise "no example #{description}" - end - - it "passes isolated examples that pass and leaves untagged examples in the runner" do - expect(example_named("passes")["status"]).to eq("passed") - expect(example_named("runs in the parent process")["status"]).to eq("passed") - end - - it "reports an expectation failure with its message" do - example = example_named("fails an expectation") - - expect(example["status"]).to eq("failed") - expect(example.dig("exception", "class")).to eq("RSpec::Expectations::ExpectationNotMetError") - expect(example.dig("exception", "message")).to include("expected: 2", "got: 1") - end - - it "reports an unexpected error with its class, message and backtrace" do - example = example_named("raises an error") - - expect(example["status"]).to eq("failed") - expect(example["exception"]).to include("class" => "ArgumentError", "message" => "boom") - expect(example.dig("exception", "backtrace")).not_to be_empty - end - - it "reports errors raised in hooks" do - example = example_named("reports the hook error") - - expect(example["status"]).to eq("failed") - expect(example.dig("exception", "message")).to eq("hook failed") - end - - it "reports a child that dies without reporting" do - example = example_named("dies without reporting") - - expect(example["status"]).to eq("failed") - expect(example.dig("exception", "message")).to match(/exited without reporting.*exit 3/) - end - - it "records coverage from the child process" do - expect(@coverage_runs).to include(a_string_matching(/subprocess/)) - end - -it "reports every error of an example that fails more than once" do - example = example_named("reports both errors") - - expect(example["status"]).to eq("failed") - expect(example.dig("exception", "message")).to include("body failed", "after hook failed") -end - -it "runs a group-isolated group in a child process with shared before(:all) state" do - expect(example_named("runs the group in a child process")["status"]).to eq("passed") - expect(example_named("shares before(:all) state across examples")["status"]).to eq("passed") - expect(example_named("keeps state from earlier examples of the group")["status"]).to eq("passed") -end - -it "keeps state from a group-isolated group out of the runner" do - expect(example_named("sees no state from the group")["status"]).to eq("passed") -end - -it "reports failures and skips inside a group-isolated group" do - failed = example_named("fails inside the group") - skipped = example_named("skips inside the group") - - expect(failed["status"]).to eq("failed") - expect(failed.dig("exception", "message")).to include("expected: :b", "got: :a") - expect(skipped["status"]).to eq("pending") - expect(skipped["pending_message"]).to eq("group skip") -end - - it "keeps skipped examples skipped with their reason" do - example = example_named("skips") - - expect(example["status"]).to eq("pending") - expect(example["pending_message"]).to eq("not today") - end - end -end diff --git a/sentry-rails/spec/spec_helper.rb b/sentry-rails/spec/spec_helper.rb index e0ab55400..cde34bdbd 100644 --- a/sentry-rails/spec/spec_helper.rb +++ b/sentry-rails/spec/spec_helper.rb @@ -18,7 +18,7 @@ SimpleCov.start do project_name "sentry-rails" root File.join(__FILE__, "../../../") - coverage_dir ENV.fetch("SENTRY_RAILS_COVERAGE_DIR") { File.join(__FILE__, "../../coverage") } + coverage_dir File.join(__FILE__, "../../coverage") end diff --git a/sentry-rails/spec/support/isolation.rb b/sentry-rails/spec/support/isolation.rb index 4ff923431..95ddda68a 100644 --- a/sentry-rails/spec/support/isolation.rb +++ b/sentry-rails/spec/support/isolation.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "json" + # Runs specs in a forked child process, so the process-global state a Rails app # boot leaves behind (load hooks, callbacks, singletons) dies with the child # instead of leaking into later examples. @@ -21,8 +23,7 @@ # # This hooks into RSpec::Core::Example#run, RSpec::Core::ExampleGroup.run and # the private Example#start/finish/set_exception, because an `around` hook -# can't skip the example body in the parent. The specs in spec/isolation_spec.rb -# guard that seam across RSpec upgrades. +# can't skip the example body in the parent. module Test module Isolation TIMEOUT = 120 @@ -107,10 +108,9 @@ def run_in_child @in_child = true reader.close Coverage.start_in_child - data = Marshal.dump(yield) - writer.write(data) + result = yield + writer.write(Marshal.dump(result: result, coverage: Coverage.result_from_child)) writer.close - Coverage.save_from_child $stdout.flush $stderr.flush exit!(0) @@ -178,7 +178,11 @@ def wait_for_result(reader, pid) if IO.select([reader], nil, nil, TIMEOUT) data = reader.read status = Process.wait2(pid).last - return Marshal.load(data) unless data.empty? + unless data.empty? + payload = Marshal.load(data) + Coverage.absorb(payload[:coverage]) + return payload[:result] + end crashed("isolated spec exited without reporting (#{status.inspect})") else @@ -205,21 +209,32 @@ def rebuild_error(error) end end - # The child exits with `exit!`, which skips SimpleCov's at_exit hook, so it - # starts its own measurement (the same thing SimpleCov's subprocess support - # does) and stores its result for the parent to merge at exit. module Coverage module_function def start_in_child + ::Coverage.result(stop: false, clear: true) if simplecov_running? + end + + def result_from_child return unless simplecov_running? - ::Coverage.result(stop: false, clear: true) - SimpleCov.at_fork.call(Process.pid) + root = SimpleCov.root + project_files = ::Coverage.result(stop: false, clear: true).select { |file, _| file.start_with?(root) } + JSON.parse(JSON.dump(SimpleCov::ResultAdapter.call(project_files))) + end + + def absorb(coverage) + return unless coverage + + @children = SimpleCov::Combine::ResultsCombiner.combine(@children || {}, coverage) end - def save_from_child - SimpleCov.result if simplecov_running? + def store_children + return unless @children && simplecov_running? + + result = SimpleCov::Result.new(@children, command_name: "#{SimpleCov.command_name} (isolated)") + SimpleCov::ResultMerger.store_result(result) end def simplecov_running? @@ -231,3 +246,5 @@ def simplecov_running? RSpec::Core::Example.prepend(Test::Isolation::ExampleExtension) RSpec::Core::ExampleGroup.singleton_class.prepend(Test::Isolation::GroupExtension) + +at_exit { Test::Isolation::Coverage.store_children }