Let an empty body satisfy a body assertion - #79
Merged
Conversation
--assert-body-eq '' could never pass, and neither could --assert-body
with a pattern that matches the empty string. Both checked whether the
body was empty before checking what had been asked of it:
$ http-assert --assert-body-eq '' http://…/empty # a 204
- body: expected "", missing
The message refutes itself -- the empty string is not missing, it is
what was asked for -- and a 204 could not be asserted to have the body
a 204 is defined to have. `^$`, `.*` and `\A\z` were unreachable for the
same reason.
The guard exists to word the failure well: "missing" reads better than
`got ""` when content was expected and none arrived. That is a wording
choice, and it had been deciding the verdict. It now runs inside the
failure branch, so the message survives and the comparison is what
decides.
Closes #22
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP
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.
Problem
--assert-body-eq ''could never pass, and the failure said so in a way that refuted itself.Both
--assert-body-eqand--assert-bodychecked whether the body was empty before checking what had been asked of them:The empty string is not missing — it is exactly what was asked for. So a
204 No Contentcould not be asserted to have the body a 204 is defined to have.--assert-bodyhas the same shape, which makes every pattern that legitimately matches an empty body unreachable:^$,.*,\A\zand the empty pattern all fail against a 204 no matter what the response is.Solution
Let the comparison decide the verdict, and keep the guard for what it was actually good at.
"missing" reads better than
got ""when content was expected and none arrived — that is a genuine improvement to the failure message, and it is worth keeping. It just had no business running before the comparison. It now runs inside the failure branch:The inverse still fails, so this is not "stopped checking dressed up as fixed".
Other Changes
TestKnownIssue22EmptyBodyEqualsNeverPassesis deleted and replaced byTestE2EAssertEmptyBody, which covers both directions: the expectations an empty body now satisfies, and the ones it still must not.Unit coverage adds the four patterns an empty body legitimately matches, both an empty and a nil
BodyBytes(a 204 produces the latter), and a check that the "missing" wording survived. The existing table needed no changes — empty-body-versus-"value"still reports exactly what it did before, which is the evidence the message was preserved rather than sacrificed.No README change: nothing in it described the broken behaviour, so there is nothing to correct.
There are no screenshots because there is no rendered UI; this tool's user-visible surface is terminal output, shown inline above.
Closes #22
Related:
🤖 Generated with Claude Code
https://claude.ai/code/session_019EMMhgmTkbzAsmeNy97PrP