Module: Minitest::Sus::Context
- Defined in:
- lib/minitest/sus.rb
Overview
Include this into a ‘Minitest::Test` subclass to host sus fixtures, before the fixtures themselves so they sit above it in the ancestor chain.
It is opt-in per test class — nothing about Minitest::Test is patched globally, so tests that don’t use it are completely unaffected.
It is the terminal of the fixture hook chain: it mirrors ‘Sus::Base`’s ‘before`/`after`/`around` contract, bridges `mock`, and wraps the whole Minitest run (setup + test + teardown) in the `around` chain so fixtures such as the async reactor are active throughout.
Instance Method Summary collapse
-
#after(error = nil) ⇒ Object
A hook which is called after the test is executed.
-
#around(&block) ⇒ Object
Wrap logic around the test being executed.
-
#before ⇒ Object
A hook which is called before the test is executed.
-
#mock(target, &block) ⇒ Object
Bridge sus’s ‘mock` API onto the Minitest instance.
-
#run ⇒ Object
Run the test, wrapping the entire Minitest lifecycle in the ‘around` chain so fixture state (reactor, server, client, …) is available to setup, the test body and teardown alike.
Instance Method Details
#after(error = nil) ⇒ Object
A hook which is called after the test is executed. Fixtures override this and call ‘super`.
48 49 |
# File 'lib/minitest/sus.rb', line 48 def after(error = nil) end |
#around(&block) ⇒ Object
Wrap logic around the test being executed. This is the terminal implementation: it runs ‘before`, yields, then `after`. Fixtures override this and call `super(&block)` to compose.
54 55 56 57 58 59 60 61 62 |
# File 'lib/minitest/sus.rb', line 54 def around(&block) self.before return block.call rescue => error raise ensure self.after(error) end |
#before ⇒ Object
A hook which is called before the test is executed. Fixtures override this and call ‘super`.
42 43 |
# File 'lib/minitest/sus.rb', line 42 def before end |
#mock(target, &block) ⇒ Object
Bridge sus’s ‘mock` API onto the Minitest instance. The first call upgrades the instance with `Sus::Mocks`, which also installs the `after` cleanup that clears the mocks.
68 69 70 71 72 73 |
# File 'lib/minitest/sus.rb', line 68 def mock(target, &block) self.singleton_class.prepend(::Sus::Mocks) # Redirect to the freshly prepended implementation: self.mock(target, &block) end |
#run ⇒ Object
Run the test, wrapping the entire Minitest lifecycle in the ‘around` chain so fixture state (reactor, server, client, …) is available to setup, the test body and teardown alike.
78 79 80 81 82 83 84 85 86 |
# File 'lib/minitest/sus.rb', line 78 def run result = nil around do result = super end return result end |