feat: add Offside.Testing assertions package - #16
Merged
Merged
Conversation
Add Offside.Testing: fluent assertions over Result, Result<T>, Error and
JSON message catalogs, with no test-framework dependency. Failures throw
OffsideAssertionException, which xUnit, NUnit, MSTest and TUnit all report
as a failed test.
Entry points are named ShouldHaveError rather than Should(), so the package
coexists with FluentAssertions or Shouldly in the same file. Every failure
message carries the actual contents of the subject, which is the point:
Assert.True(result.IsFailure) reports nothing about which errors were
carried.
OffsideCatalog reads catalogs directly instead of going through
IErrorMessageResolver, whose fallback returns Error.Code on a miss and makes
a missing code indistinguishable from a template equal to the code. That
also enables coverage assertions: unfilled {token} detection and comparing a
translated catalog against the invariant one.
Ship an offside-testing agent skill via offside init, migrate the
repository's own tests off Assert.True(result.IsFailure), and document the
package in both languages.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_0bfd0aea-e299-4e71-b184-b65d03ec7097) |
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.
Adds
Offside.Testing: fluent assertions overResult,Result<T>,Error, and JSON message catalogs.The point is not shorter test code — it is what you read when a test fails.
Assert.True(result.IsFailure)reportsAssert.True() Failure; this reports which errors the result actually carried.Design decisions
Offside.FluentAssertionspackage would push that onto consumers. Failures throwOffsideAssertionException; xUnit, NUnit, MSTest and TUnit all report any exception as a failed test, so the package works in all four with zero test-framework references.ShouldHaveError, notShould(). Deliberately avoids colliding with FluentAssertions' and Shouldly's entry point, so both can be used in the same file.ShouldHaveError("x").WithKind(k)can say "the error exists, but its kind isConflict, expectedValidation" instead of "no error matched".OffsideCatalogreads the JSON directly rather than going throughIErrorMessageResolver, whose fallback returnsError.Codeon a miss — that makes a missing code indistinguishable from a template equal to the code. Reading the catalog also enables coverage assertions no resolver could support.IErrorMessageResolverwithTryGetMessagewas considered and rejected: breaking for external implementors, and ISP-wise it forces every implementation to support a method only tests need.API
ShouldBeSuccess()Result<T>, exposes the value viaSubject/WithValue.ShouldBeFailure()ShouldHaveError(code)ShouldHaveOnlyError(code)ShouldHaveErrorsInOrder(codes)ShouldHaveErrorCount(n)Refinements:
WithKind,WithErrorCode,ForField,WithArgument,WithMessage(resolver, text)..Andreturns the result for chaining and is always optional.Catalog:
ShouldDefine,ShouldDefineAll,ShouldResolve(code exists and no{token}left unfilled),ShouldResolveAll,ShouldDefineSameCodesAs(keeps a translated catalog from drifting behind the invariant one).ShouldHaveErrorsInOrderis documented as the assertion to avoid by default: order comes fromResult.Combineargument order or FluentValidation rule declaration order, so reordering rules breaks it without any behaviour changing.Also included
offside-testingagent skill, installed byoffside initalongside the existing nine, with a what to cover section. Cross-referenced fromoffside-implementationandoffside-refactoring.Assert.True(result.IsFailure)— dogfooding.docs/testing.md/docs/pt-BR/testing.md, plus README, API reference, CLI docs and CHANGELOG.Testing
Offside.Testing.Testsuses raw xUnit on purpose: asserting the package with the package would let a "never fails" defect pass unnoticed. Every negative case asserts the message text, since the diagnostics are the product here.dotnet buildanddotnet testpass across the solution onnet8.0andnet10.0, 0 warnings, 0 errors. The package itself also builds fornetstandard2.0.🤖 Generated with Claude Code
Note
Low Risk
Additive test-only package and documentation; core runtime APIs are unchanged, with risk limited to consumers adopting the new assertion surface.
Overview
Introduces
Offside.Testing, a new optional NuGet package with fluent assertions forResult,Result<T>,Error, and JSON message catalogs. Failures throwOffsideAssertionException(no xUnit/NUnit dependency); APIs useShouldHaveError/ShouldBeSuccessinstead ofShould()so they can sit beside FluentAssertions or Shouldly.ErrorAssertionlocates an error by code first, then refines withWithKind,ForField,WithArgument, andWithMessage.OffsideCatalogloads catalog JSON directly forShouldDefine,ShouldResolve(unfilled{token}detection), andShouldDefineSameCodesAsacross cultures.The solution adds
Offside.TestingandOffside.Testing.Tests; several existing test projects reference the package and replaceAssert.True(result.IsFailure)with the new extensions.offside initnow installs a tenth skill (offside-testing), withSkillInstallerand implementation/refactoring skills updated accordingly. Docs and changelog cover install, API reference, and bilingualdocs/testing.md/docs/pt-BR/testing.md.Reviewed by Cursor Bugbot for commit bffd7ef. Bugbot is set up for automated code reviews on this repo. Configure here.