Skip to content

Commit

Permalink
Lazy load ActionController::TestCase (#1613)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilianah committed Mar 15, 2024
1 parent b18c50c commit 2793b9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 7 additions & 5 deletions lib/shoulda/matchers/integrations/libraries/action_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/shoulda/matchers/integrations/libraries/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2793b9b

Please sign in to comment.