Skip to content

Allow simple stub helpers in around hooks - #48

Merged
YusukeIwaki merged 7 commits into
mainfrom
codex/issue-40-hook-scoped-stubs
Jul 31, 2026
Merged

YusukeIwaki merged 7 commits into
mainfrom
codex/issue-40-hook-scoped-stubs

Conversation

@YusukeIwaki

@YusukeIwaki YusukeIwaki commented Jul 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • make simple_stub and simple_stub_any_instance_of available inside around_test and around_suite
  • reset hook-scoped stubs automatically in reverse order, including failure, skip, and missing-run-target paths
  • preserve primary test and hook failures when stub teardown also fails, reporting reset errors separately
  • roll back an applied stub immediately if its lifecycle owner cannot register it for teardown
  • separate user-facing SimpleStubDSL operations from lifecycle state owned by a per-invocation HookContext
  • expose cleanup errors from fixture sets and hook contexts, then pull them into results with TeardownErrorAggregator
  • make fixture and hook teardown at-most-once and reentry-safe while preserving the first teardown errors
  • move hook composition and lifecycle orchestration from Runner into dedicated around-suite and around-test hook chains
  • keep lifecycle implementation classes out of public RBS and list stub helpers directly on fixtures and hook contexts
  • document fixture-scoped stubs as the default and hook-scoped stubs as an optional, autouse-fixture-style setup
  • record the feature under Unreleased rather than the already-published 0.7.0 release

Why

Broad method stubs previously needed a fixture whose only purpose was to activate the stub. Hook-scoped helpers let suites express intentionally implicit setup without adding a dummy fixture keyword to every test, while preserving automatic teardown.

Closes #40.

User impact

Users can now call the existing simple stub helpers before test.run or suite.run. Stubs remain active for that hook invocation and restore any outer hook, fixture, or suite-fixture stub when the scope exits. If the primary operation and cleanup both fail, both errors remain visible in the report.

Internally, lifecycle operations no longer receive a shared mutable teardown-error array. Each completed fixture or hook scope exposes its own errors through teardown_errors, and a dedicated aggregator collects those values for reporting. A stub is also reset transactionally if registration with that lifecycle fails. Teardown owners drain their queues before callbacks, so repeated and reentrant teardown calls do not execute cleanup twice or discard previously recorded errors.

Validation

  • Ruby 2.7.8: 131 passed
  • Ruby 3.3.0: 131 passed
  • Ruby 4.0.0: 131 passed
  • RBENV_VERSION=3.3.0 rbs -I sig validate
  • npm run build from documentation/
  • git diff --check

@vercel

vercel Bot commented Jul 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
smartest Ready Ready Preview, Comment Jul 25, 2026 11:04pm

@YusukeIwaki
YusukeIwaki marked this pull request as ready for review July 25, 2026 23:07
@YusukeIwaki
YusukeIwaki merged commit 2176c5b into main Jul 31, 2026
9 checks passed
@YusukeIwaki
YusukeIwaki deleted the codex/issue-40-hook-scoped-stubs branch July 31, 2026 11:45

This branch was successfully deployed

1 active deployment
Preview — 70656fca Deployed Jul 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow simple stub helpers in around hooks

1 participant