From b430027965a8544606c337063e256053b0f1cd68 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Sat, 6 Apr 2024 10:42:26 -0400 Subject: [PATCH 1/4] Wrap examples with Rails executor This recreates #2712 since the GHA logs are no longer available which we need to address this issue. We should be wrapping the Rails examples with the executor to mimic what Rails v7 does (as noted in #2713) to properly reset state. This has been tested in a test suite for an app but we need to address what issues there is within rspec-rails. This change request originated from #2503 and #2752 which the latter is meant as a temporary fix since this is the expected way to reset state. --- lib/rspec/rails/example/rails_example_group.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index ed343de35..ff0fba53b 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -2,11 +2,6 @@ # suite and ammeter. require 'rspec/rails/matchers' -if ::Rails::VERSION::MAJOR >= 7 - require 'active_support/current_attributes/test_helper' - require 'active_support/execution_context/test_helper' -end - module RSpec module Rails # @api public @@ -17,10 +12,16 @@ module RailsExampleGroup include RSpec::Rails::MinitestLifecycleAdapter include RSpec::Rails::MinitestAssertionAdapter include RSpec::Rails::FixtureSupport + include RSpec::Rails::TaggedLoggingAdapter if ::Rails::VERSION::MAJOR >= 7 + if ::Rails::VERSION::MAJOR >= 7 include RSpec::Rails::TaggedLoggingAdapter - include ActiveSupport::CurrentAttributes::TestHelper include ActiveSupport::ExecutionContext::TestHelper + included do |_other| + around do |example| + ::Rails.application.executor.perform { example.call } + end + end end end end From f35b3a652e6357581d155324b4bcdf60ef59856c Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Sat, 6 Apr 2024 10:49:05 -0400 Subject: [PATCH 2/4] Account for Rails config default switch From: https://github.com/rspec/rspec-rails/pull/2712/files#r1425001008 --- lib/rspec/rails/example/rails_example_group.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index ff0fba53b..00c2248dc 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -19,7 +19,11 @@ module RailsExampleGroup include ActiveSupport::ExecutionContext::TestHelper included do |_other| around do |example| - ::Rails.application.executor.perform { example.call } + if ::Rails.configuration.active_support.executor_around_test_case + ::Rails.application.executor.perform { example.call } + else + example.call + end end end end From 13958cc055a9fe0052b9817e91c9aa2974e481f8 Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Mon, 8 Apr 2024 10:29:02 -0400 Subject: [PATCH 3/4] Account for all known cases This now matches what Rails 7+ does --- lib/rspec/rails/example/rails_example_group.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index 00c2248dc..c32886279 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -12,19 +12,22 @@ module RailsExampleGroup include RSpec::Rails::MinitestLifecycleAdapter include RSpec::Rails::MinitestAssertionAdapter include RSpec::Rails::FixtureSupport - include RSpec::Rails::TaggedLoggingAdapter if ::Rails::VERSION::MAJOR >= 7 if ::Rails::VERSION::MAJOR >= 7 include RSpec::Rails::TaggedLoggingAdapter - include ActiveSupport::ExecutionContext::TestHelper - included do |_other| - around do |example| - if ::Rails.configuration.active_support.executor_around_test_case + + if ::Rails.configuration.active_support.executor_around_test_case + included do |_other| + around do |example| ::Rails.application.executor.perform { example.call } - else - example.call end end + else + require 'active_support/current_attributes/test_helper' + include ActiveSupport::CurrentAttributes::TestHelper + + require 'active_support/execution_context/test_helper' + include ActiveSupport::ExecutionContext::TestHelper end end end From 0cf0662edaf07dea1aefb1d2a05f65bbbbb6443b Mon Sep 17 00:00:00 2001 From: Javier Julio Date: Wed, 10 Apr 2024 11:15:00 -0400 Subject: [PATCH 4/4] Update require/include statements --- lib/rspec/rails/example/rails_example_group.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/rspec/rails/example/rails_example_group.rb b/lib/rspec/rails/example/rails_example_group.rb index c32886279..3530ee28f 100644 --- a/lib/rspec/rails/example/rails_example_group.rb +++ b/lib/rspec/rails/example/rails_example_group.rb @@ -2,6 +2,11 @@ # suite and ammeter. require 'rspec/rails/matchers' +if ::Rails::VERSION::MAJOR >= 7 + require 'active_support/current_attributes/test_helper' + require 'active_support/execution_context/test_helper' +end + module RSpec module Rails # @api public @@ -23,10 +28,7 @@ module RailsExampleGroup end end else - require 'active_support/current_attributes/test_helper' include ActiveSupport::CurrentAttributes::TestHelper - - require 'active_support/execution_context/test_helper' include ActiveSupport::ExecutionContext::TestHelper end end