Repository navigation
Split specs into per-class unit specs and integration specs - #188
Merged
Merged
Conversation
Most behavior was only tested through Docx::Document and real .docx fixtures. Restructure the suite so it mirrors lib/: - spec/docx/containers, spec/docx/elements: unit specs per class that build nodes from WordprocessingML fragments (spec/support/xml_helpers.rb), pass document_properties as a hash and use instance_double for the Document. - spec/docx/document_spec.rb: only what Document owns (opening the package, loading parts, document-wide lookups, save/stream). - spec/integration: end-to-end scenarios on real fixtures, including save-and-reopen round trips. Also: load docx/document in spec_helper so element classes can be referenced directly, write saved files to a per-example temp dir instead of spec/fixtures, move the misplaced no_styles font_size check out of the 'reading' shared examples, and document the layout for contributors. No library code changes. 164 -> 266 examples; line coverage 96.36% -> 98.92%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 17, 2026
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.
Why
Most behavior was only tested through
Docx::Documentand real.docxfixtures. That works as an end-to-end test, but it means a failure doesn't point at the class that broke, and element behavior can't be tested without crafting a fixture.What
The suite now mirrors
lib/, one spec per class, in three layers:spec/docx/containers/*,spec/docx/elements/*,spec/docx/helpers_spec.rbw_node/w_bodyinspec/support/xml_helpers.rb).document_propertiesis passed as a plain hash, and the Document is aninstance_double.spec/docx/document_spec.rbDocumentowns: opening the package, loading parts (styles, rels, headers, footers), document-wide lookups, andsave/stream/replace_entry.spec/integration/*Housekeeping:
spec_helpernow loadsdocx/document.lib/docx.rbonly autoloadsDocument, sostyle_specworked only when it happened to run afterdocument_spec.tmp_path) instead ofspec/fixtures.no_stylesfont_sizecheck was inside the'reading'shared examples and described as "should raise an error" while assertingnil. It moved toDocument#font_size.tdd-developmentskill andCLAUDE.mdwith where new tests go.No library code changes.
Verification
lib/(substitute search offset, html alignment/size/strike, cell → paragraph property passing, column indexing, block-bookmarkpPrhandling,html_tag,style_oflookup, inspect truncation, left alignment). The unit specs alone catch every one.Bugs found while writing unit specs (not fixed here)
These are behavior changes, so each is tracked as its own issue and will get a test-first PR:
Element#prepend_tocallselement.node.properties, which doesn't exist on Nokogiri nodes, so the method always raises.TextRun#text=on a run with now:twrites the XML, but#textstill returns""because@text_nodesisn't refreshed.SimpleInspect#inspect(true)raisesArgumentError: the baresuperforwards the argument toObject#inspect.word/_rels/document.xml.relsis missing,load_relsrescues and leaves@relsnil, and then#hyperlinks(and so#paragraphs) raisesNoMethodError.🤖 Generated with Claude Code