Repository navigation
refactor: share one set of stubs and configuration helpers across core tests - #471
Merged
Merged
Conversation
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.
📚 Preview this PR's docs locallyFetch 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 471Auth & tips
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a shared test module with three helpers and moves the core tests onto them. It changes no library code.
stubbed_buildrunsGreatDocs.build()with Quarto and every step stubbed,mock_configstands in for aConfigwith every setting off, andwrite_configwritesgreat-docs.ymland loads it.Each test of
build()with mocked steps carried its own stack of about a dozen patches and aMagicMockconfiguration. 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 ofGreatDocsedits one line, and a stub for a method that no longer exists raises instead of patching nothing.