Skip to content
  • Tristan Starck's avatar
    b0b481a7
    Fix teardown callbacks (#50915) · b0b481a7
    Tristan Starck authored
    * Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks.
    
    Minitest provides `setup` and `teardown` lifecycle hooks to run code in. In general it is best practice to when defining your own test case class, to use `Minitest::TestCase.setup` and `Minitest::TestCase.teardown` instead of `before_setup` and `after_teardown`.
    
    Per Minitest's Documentation on Lifecycle Hooks: https://docs.ruby-lang.org/en/2.1.0/MiniTest/Unit/LifecycleHooks.html
    > before_setup()
    > Runs before every test, before setup. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.
    
    > after_teardown()
    > Runs after every test, after teardown. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.
    
    Since the `setup` and `teardown` ActiveSupport::TestCase callbacks are in essence user code, it makes sense to run during their corresponding Minitest Lifecycle hooks.
    
    * Ensure test fixutres are torndown on errors in superclass after_teardown code.
    
    By not adding wrapping the `teardown_fixtures` code, its possible that super raises an error and prevents the existing database transaction from rolling back.
    `super` in general should only be calling `Minitest::Testcase.after_teardown` however, if another library were to override `Minitest::Testcase.after_teardown`, like the popular gem [rspec-mocks](https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/minitest_integration.rb#L23
    
    ) does, it causes all subsequent tests to retain any changes that were made to the database in the original test that errors.
    
    * Remove unnecessary setup and teardown methods in tests
    
    * update activesupport Changelog
    
    * Fix linter issues in CHANGELOG
    
    * fix tests with improper setup and teardown method definitions
    
    * Fix final CHANGELOG lint
    
    * Revert "Fix final CHANGELOG lint"
    
    This reverts commit f30682eb629780862ccc63e1d3210dfe035e997e.
    
    * Revert "fix tests with improper setup and teardown method definitions"
    
    This reverts commit 1d5b88c8739695a4eed5c46924c9ffc6010353f5.
    
    * Revert "Fix linter issues in CHANGELOG"
    
    This reverts commit 60e89bd189cbcdf50d7e923a90ec5ebe1578a6e9.
    
    * Revert "update activesupport Changelog"
    
    This reverts commit 0f19bc324fec7a793cc34dcfede27017b5a24e46.
    
    * Revert "Remove unnecessary setup and teardown methods in tests"
    
    This reverts commit e5673f179ac01c814ab44017b97e7638aad6e775.
    
    * Revert "Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks."
    
    This reverts commit d08d92d86131d8643a275397d9b0c15995730a14.
    
    * Rescue Minitest::Assertion errors in ActiveSupport::TestCase.teardown callback code to ensure all other after_teardown methods are called.
    
    * Fix name of test class
    
    * remove unused MyError class
    
    * Fix module to not be in global namespace
    
    Co-authored-by: default avatarRafael Mendonça França <rafael@rubyonrails.org>
    b0b481a7
    Fix teardown callbacks (#50915)
    Tristan Starck authored
    * Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks.
    
    Minitest provides `setup` and `teardown` lifecycle hooks to run code in. In general it is best practice to when defining your own test case class, to use `Minitest::TestCase.setup` and `Minitest::TestCase.teardown` instead of `before_setup` and `after_teardown`.
    
    Per Minitest's Documentation on Lifecycle Hooks: https://docs.ruby-lang.org/en/2.1.0/MiniTest/Unit/LifecycleHooks.html
    > before_setup()
    > Runs before every test, before setup. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.
    
    > after_teardown()
    > Runs after every test, after teardown. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.
    
    Since the `setup` and `teardown` ActiveSupport::TestCase callbacks are in essence user code, it makes sense to run during their corresponding Minitest Lifecycle hooks.
    
    * Ensure test fixutres are torndown on errors in superclass after_teardown code.
    
    By not adding wrapping the `teardown_fixtures` code, its possible that super raises an error and prevents the existing database transaction from rolling back.
    `super` in general should only be calling `Minitest::Testcase.after_teardown` however, if another library were to override `Minitest::Testcase.after_teardown`, like the popular gem [rspec-mocks](https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/minitest_integration.rb#L23
    
    ) does, it causes all subsequent tests to retain any changes that were made to the database in the original test that errors.
    
    * Remove unnecessary setup and teardown methods in tests
    
    * update activesupport Changelog
    
    * Fix linter issues in CHANGELOG
    
    * fix tests with improper setup and teardown method definitions
    
    * Fix final CHANGELOG lint
    
    * Revert "Fix final CHANGELOG lint"
    
    This reverts commit f30682eb629780862ccc63e1d3210dfe035e997e.
    
    * Revert "fix tests with improper setup and teardown method definitions"
    
    This reverts commit 1d5b88c8739695a4eed5c46924c9ffc6010353f5.
    
    * Revert "Fix linter issues in CHANGELOG"
    
    This reverts commit 60e89bd189cbcdf50d7e923a90ec5ebe1578a6e9.
    
    * Revert "update activesupport Changelog"
    
    This reverts commit 0f19bc324fec7a793cc34dcfede27017b5a24e46.
    
    * Revert "Remove unnecessary setup and teardown methods in tests"
    
    This reverts commit e5673f179ac01c814ab44017b97e7638aad6e775.
    
    * Revert "Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks."
    
    This reverts commit d08d92d86131d8643a275397d9b0c15995730a14.
    
    * Rescue Minitest::Assertion errors in ActiveSupport::TestCase.teardown callback code to ensure all other after_teardown methods are called.
    
    * Fix name of test class
    
    * remove unused MyError class
    
    * Fix module to not be in global namespace
    
    Co-authored-by: default avatarRafael Mendonça França <rafael@rubyonrails.org>
Loading