diff options
| author | Alyssa Ross | 2017-01-21 11:21:30 +0000 |
|---|---|---|
| committer | Alyssa Ross | 2017-01-21 11:34:52 +0000 |
| commit | 70a381a00ff1e354e059aa07d55ebab90c5f874a (patch) | |
| tree | 32275fe167b961605ddeb2cf71fe1c1437d91c2a /Library/Homebrew/test/support | |
| parent | d7c463ad2c036bd9917398069217f6cad0f5b326 (diff) | |
| download | brew-70a381a00ff1e354e059aa07d55ebab90c5f874a.tar.bz2 | |
tests: enforce `super` in lifecycle hooks
This will allow us to have global setup and teardown for tests.
For example, we can automatically clear caches after each test, to avoid
annoying intermittent failures like #1879 and #1886.
Diffstat (limited to 'Library/Homebrew/test/support')
3 files changed, 26 insertions, 0 deletions
diff --git a/Library/Homebrew/test/support/helper/integration_command_test_case.rb b/Library/Homebrew/test/support/helper/integration_command_test_case.rb index 6879f2f81..86184ac51 100644 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -6,6 +6,7 @@ require "test/support/helper/test_case" class IntegrationCommandTestCase < Homebrew::TestCase def setup + super @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`. (HOMEBREW_PREFIX/"bin").mkpath FileUtils.touch HOMEBREW_PREFIX/"bin/brew" @@ -38,6 +39,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase coretap.path/"formula_renames.json", ].flatten FileUtils.rm_rf paths_to_delete + super end def needs_test_cmd_taps diff --git a/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb new file mode 100644 index 000000000..413f8b11e --- /dev/null +++ b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb @@ -0,0 +1,22 @@ +module Test + module Helper + module LifecycleEnforcer + def setup + @__setup_called = true + super + end + + def teardown + @__teardown_called = true + super + end + + def after_teardown + assert @__setup_called, "Expected setup to call `super` but didn't" + assert @__teardown_called, "Expected teardown to call `super` but didn't" + + super + end + end + end +end diff --git a/Library/Homebrew/test/support/helper/test_case.rb b/Library/Homebrew/test/support/helper/test_case.rb index 60c91e7bb..5becfeef1 100644 --- a/Library/Homebrew/test/support/helper/test_case.rb +++ b/Library/Homebrew/test/support/helper/test_case.rb @@ -2,10 +2,12 @@ module Homebrew class TestCase < ::Minitest::Test require "test/support/helper/env" require "test/support/helper/fs_leak_logger" + require "test/support/helper/lifecycle_enforcer" require "test/support/helper/shutup" require "test/support/helper/version_assertions" include Test::Helper::Env include Test::Helper::FSLeakLogger + include Test::Helper::LifecycleEnforcer include Test::Helper::Shutup include Test::Helper::VersionAssertions |
