diff --git a/lib/shoulda/matchers/integrations/libraries/action_controller.rb b/lib/shoulda/matchers/integrations/libraries/action_controller.rb index 013832e0e..ff62c4100 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 + self.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..0e0501346 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) + self.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