Skip to content

Commit 2793b9b

Browse files
authored
Lazy load ActionController::TestCase (#1613)
1 parent b18c50c commit 2793b9b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

lib/shoulda/matchers/integrations/libraries/action_controller.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ class ActionController
1212
def integrate_with(test_framework)
1313
test_framework.include(matchers_module, type: :controller)
1414

15-
include_into(::ActionController::TestCase, matchers_module) do
16-
def subject # rubocop:disable Lint/NestedMethodDefinition
17-
@controller
15+
tap do |instance|
16+
ActiveSupport.on_load(:action_controller_test_case, run_once: true) do
17+
instance.include_into(::ActionController::TestCase, instance.matchers_module) do
18+
def subject # rubocop:disable Lint/NestedMethodDefinition
19+
@controller
20+
end
21+
end
1822
end
1923
end
2024
end
2125

22-
private
23-
2426
def matchers_module
2527
Shoulda::Matchers::ActionController
2628
end

lib/shoulda/matchers/integrations/libraries/routing.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ class Routing
1212
def integrate_with(test_framework)
1313
test_framework.include(matchers_module, type: :routing)
1414

15-
include_into(::ActionController::TestCase, matchers_module)
15+
tap do |instance|
16+
ActiveSupport.on_load(:action_controller_test_case, run_once: true) do
17+
instance.include_into(::ActionController::TestCase, instance.matchers_module)
18+
end
19+
end
1620
end
1721

18-
private
19-
2022
def matchers_module
2123
Shoulda::Matchers::Routing
2224
end

0 commit comments

Comments
 (0)