Add load hooks to all tests classes

Usually users extends tests classes doing something like:

    ActionView::TestCase.include MyCustomTestHelpers

This is bad because it will load the ActionView::TestCase right aways
and this will load ActionController::Base making its on_load hooks to
execute early than it should.

One way to fix this is using the on_load hooks of the components like:

    ActiveSupport.on_load(:action_view) do
      ActionView::TestCase.include MyCustomTestHelpers
    end

The problem with this approach is that the test extension will be only
load when ActionView::Base is loaded and this may happen too late in the
test.

To fix this we are adding hooks to people extend the test classes that
will be loaded exactly when the test classes are needed.
This commit is contained in:
Rafael Mendonça França 2016-08-25 04:22:48 -03:00
parent 804f5b3c2a
commit 0510208dd1
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
4 changed files with 5 additions and 0 deletions

View File

@ -41,6 +41,7 @@ module ActionMailer
setup :initialize_test_deliveries setup :initialize_test_deliveries
setup :set_expected_mail setup :set_expected_mail
teardown :restore_test_deliveries teardown :restore_test_deliveries
ActiveSupport.run_load_hooks(:action_mailer_test_case, self)
end end
module ClassMethods module ClassMethods

View File

@ -627,6 +627,7 @@ module ActionController
include ActionDispatch::Assertions include ActionDispatch::Assertions
class_attribute :_controller_class class_attribute :_controller_class
setup :setup_controller_request_and_response setup :setup_controller_request_and_response
ActiveSupport.run_load_hooks(:action_view_test_case, self)
end end
private private

View File

@ -152,6 +152,7 @@ module ActionView
included do included do
setup :setup_with_controller setup :setup_with_controller
ActiveSupport.run_load_hooks(:action_view_test_case, self)
end end
private private

View File

@ -3,5 +3,7 @@ require "active_support/test_case"
module ActiveJob module ActiveJob
class TestCase < ActiveSupport::TestCase class TestCase < ActiveSupport::TestCase
include ActiveJob::TestHelper include ActiveJob::TestHelper
ActiveSupport.run_load_hooks(:active_job_test_case, self)
end end
end end