Skip to content

Fix NameError in place of a failed comparison when color is on - #7

Merged
trans merged 1 commit into
masterfrom
fix-ansi-diff
Nov 25, 2026
Merged

trans merged 1 commit into
masterfrom
fix-ansi-diff

Conversation

@trans

@trans trans commented Nov 24, 2026

Copy link
Copy Markdown
Member

In 0.5.0, a failed comparison of long values (more than 13 characters when inspected) could raise NameError: uninitialized constant ANSI::Diff in place of the assertion.

Cause

EqualAssay, UnequalAssay and the AE notation color the differences between the two values when $ansi is set. The diff library was only loaded by Assay.color = true. But the ANSI gem sets $ansi itself when it loads, so under Rubytest color is on without Assay having loaded ansi/diff.

Found while porting vclog's tests: a test that should have failed was reported as an error.

Fix

  • Assay.color_diff(a, b) requires ansi/diff and returns the two colored values. The three places that built an ANSI::Diff call it.
  • test/color.rb checks each of the three in a process of its own, with $ansi set from outside, and expects the right assertion class with a colored message. Without the fix all three fail with the NameError. It runs as rake color, part of the default task.
  • Version is 0.5.1, with the HISTORY entry under Unreleased.

🤖 Generated with Claude Code

A failed comparison of long values raised NameError (ANSI::Diff) when
color was on but had not been turned on with Assay.color = true, as
under Rubytest.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit c48a573 into master Nov 25, 2026
14 checks passed
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