Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windowed comparison for differences in the middle of long strings #9

Closed
cohuman opened this issue Jul 14, 2010 · 2 comments
Closed

Comments

@cohuman
Copy link

cohuman commented Jul 14, 2010

When two strings fail to match, if the difference is somewhere in the middle of the strings, it can be annoying/impossible to track down the actual difference. I've written a little Comparison object that provides this kind of error message:

Strings differ at position 12:
expected: ..."efghijklmnopqrst"...
actual: ..."efghijklXnopqrst"...

It shows a "prelude" of a few characters, then the difference, on successive lines so they're easy to visually scan. It also does the right thing (or tries to) if the difference is near the beginning or end of the string (i.e. does or doesn't show ellipses).

http://gist.github.com/474363

For people who can't wait for this to get incorporated into RSpec proper, you can require comparison.rb and it'll override the existing RSpec == matcher.

One open question is whether the exception message should show the full actual string as well as the comparison... On one hand, it adds to screen clutter, but on the other hand, it can be important in tracking down the problem, especially if the prelude is ambiguous.

@dchelimsky
Copy link
Contributor

Hey Alex,

Do you think this is best served as part of rspec proper, or as an extension? My instinct is to have it be an extension so that folks could use it with test/unit and/or minitest as well. WDYT?

@myronmarston
Copy link
Member

I'm with @dchelimsky here -- I'm not sure this belongs in rspec, but it does sound useful.

Given that this has sat for 2 years with no one else piping in, I'm going to close this as a stale ticket.

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

No branches or pull requests

3 participants