From 2793b9b6e22c348a8de38138daa92bb25307a4ee Mon Sep 17 00:00:00 2001 From: Iliana Hadzhiatanasova Date: Fri, 15 Mar 2024 14:26:33 +0000 Subject: [PATCH] Lazy load ActionController::TestCase (#1613) --- .../integrations/libraries/action_controller.rb | 12 +++++++----- .../matchers/integrations/libraries/routing.rb | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/shoulda/matchers/integrations/libraries/action_controller.rb b/lib/shoulda/matchers/integrations/libraries/action_controller.rb index 013832e0e..5fa6ec13b 100644 --- a/lib/shoulda/matchers/integrations/libraries/action_controller.rb +++ b/lib/shoulda/matchers/integrations/libraries/action_controller.rb @@ -12,15 +12,17 @@ class ActionController def integrate_with(test_framework) test_framework.include(matchers_module, type: :controller) - include_into(::ActionController::TestCase, matchers_module) do - def subject # rubocop:disable Lint/NestedMethodDefinition - @controller + tap do |instance| + ActiveSupport.on_load(:action_controller_test_case, run_once: true) do + instance.include_into(::ActionController::TestCase, instance.matchers_module) do + def subject # rubocop:disable Lint/NestedMethodDefinition + @controller + end + end end end end - private - def matchers_module Shoulda::Matchers::ActionController end diff --git a/lib/shoulda/matchers/integrations/libraries/routing.rb b/lib/shoulda/matchers/integrations/libraries/routing.rb index 3399c22bd..fda02d8e8 100644 --- a/lib/shoulda/matchers/integrations/libraries/routing.rb +++ b/lib/shoulda/matchers/integrations/libraries/routing.rb @@ -12,11 +12,13 @@ class Routing def integrate_with(test_framework) test_framework.include(matchers_module, type: :routing) - include_into(::ActionController::TestCase, matchers_module) + tap do |instance| + ActiveSupport.on_load(:action_controller_test_case, run_once: true) do + instance.include_into(::ActionController::TestCase, instance.matchers_module) + end + end end - private - def matchers_module Shoulda::Matchers::Routing end