Skip to content

refactor: share one set of stubs and configuration helpers across core tests - #471

Merged
has2k1 merged 3 commits into
mainfrom
refactor/test-helpers
Oct 29, 2026
Merged

has2k1 merged 3 commits into
mainfrom
refactor/test-helpers

Conversation

@has2k1

@has2k1 has2k1 commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

This PR adds a shared test module with three helpers and moves the core tests onto them. It changes no library code. stubbed_build runs GreatDocs.build() with Quarto and every step stubbed, mock_config stands in for a Config with every setting off, and write_config writes great-docs.yml and loads it.

Each test of build() with mocked steps carried its own stack of about a dozen patches and a MagicMock configuration. Settings a test didn't name read as true, so steps it never meant to run ran against the mock, and the build swallowed their errors. Some API reference setup tests passed only because the mock made every project look like a Python project. With one list of stubbed steps, a later change that moves a build step out of GreatDocs edits one line, and a stub for a method that no longer exists raises instead of patching nothing.

Each test of `GreatDocs.build()` with mocked steps repeated about a dozen
patches and a `MagicMock` configuration. Unspecified settings were truthy,
so the skill, tags, page status, Go, Rust and MCP steps ran against the
mock, and the build swallowed their errors.

Provide two shared helpers. `stubbed_build` stubs the Quarto check, the
render process and every build method called on the instance. Tests name
the methods to run for real and the return values to override. Stubs
enforce method signatures and default to empty values of the declared
return types. A method missing from `GreatDocs` raises an error instead
of patching nothing. `mock_config` defaults settings to empty values and
rejects names absent from `Config`.

Use both helpers in the twenty mocked build tests and retain their
assertions. Let the CLI discovery test for module names finish the build
instead of stopping at the API reference step.
The hero section and API reference setup tests used `MagicMock`
configurations with only selected settings assigned. Other settings were
truthy, so the API reference setup tests implicitly treated the project
as a Python project.

Use `mock_config` so renamed settings fail during setup. Explicitly mark
the project as Python in the five API reference setup tests that enable
the reference. Otherwise, they would return at the non-Python check, and
three would pass without testing their intended behaviour.
Many core tests repeated the same setup: write `great-docs.yml` into the
project, then load it as a real configuration.

Provide `write_config` to write YAML text or a mapping and return the
loaded configuration. Use it in these tests with their YAML text
unchanged. Keep writing the file first where project creation depends
on it.
@github-actions

Copy link
Copy Markdown

📚 Preview this PR's docs locally

Fetch the just-built site and open it in your browser:

# this exact build
great-docs preview --run 40896258185

# or always the latest build for this PR
great-docs preview --pr 471
Auth & tips
  • Requires great-docs: pip install great-docs (or run via pipx/uvx).
  • Auth: run gh auth login then add --use-gh, or set GITHUB_TOKEN (needs Actions: read).
  • Jump to a page: add --path reference/index.html.
  • Latest vs exact: --pr <n> grabs the newest build; --run <id> pins this one.
  • Re-download: --refresh ignores the local cache.

@has2k1
has2k1 merged commit ce31d9b into main Oct 29, 2026
9 checks passed
@has2k1
has2k1 deleted the refactor/test-helpers branch October 29, 2026 15:12
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.

1 participant