Use `def before_setup` instead of `setup do`

`setup do` creates unnecessary allocations of proc objects in test
callbacks. This prevents that from happening and results in faster code.

Originally I had done this as `def setup` and all Railties tests passed.
See 044f9ab. Later it was reported there was an issue with this that
caused routes in tests to be nil because devs don't generally call
`super` in their test setups. Because of that I reverted the commit
until I could find a suitble replacement.

`before_setup` esentially does the same thing but without the
requirement that applications call `super` in their test setups.
This commit is contained in:
eileencodes 2015-05-02 10:26:22 -04:00
parent e260975baf
commit 76836ef7db
1 changed files with 4 additions and 2 deletions

View File

@ -27,13 +27,15 @@ if defined?(ActiveRecord::Base)
end
class ActionController::TestCase
setup do
def before_setup
@routes = Rails.application.routes
super
end
end
class ActionDispatch::IntegrationTest
setup do
def before_setup
@routes = Rails.application.routes
super
end
end