From bede4b68ed7bba64c8bb35b82a444e4d823affd7 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Thu, 16 Nov 2023 09:21:59 +0000 Subject: [PATCH] Wrap tests in executor when configured or on Rails 7 by default --- lib/rspec/rails/example/rails_example_group.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index c3d42a527..208f7c386 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -13,6 +13,23 @@ module RailsExampleGroup include RSpec::Rails::MinitestAssertionAdapter include RSpec::Rails::FixtureSupport include RSpec::Rails::TaggedLoggingAdapter if ::Rails::VERSION::MAJOR >= 7 + + included do |_other| + around do |example| + use_exectuor = + case ::Rails.configuration.active_support.executor_around_test_case + when nil then ::Rails::VERSION::MAJOR >= 7 + when true then true + when false then false + end + + if use_exectuor + ::Rails.application.executor.perform { example.call } + else + example.call + end + end + end end end end