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
Fix pretty printing of quotes in mocha_inspect
#215
Conversation
@neonichu: Thanks for taking the time to submit this - it does look as if you've identified a genuine problem. I'll try to have a proper look as soon as I can. At first glance, the new implementation is hard to follow. Also it's not obvious that the two new unit tests are sufficient to require all of the logic in the new implementation. Writing more exhaustive unit tests might help explain the implementation better. |
This is an alternative attempt at fixing the problem identified and addressed in #215 regarding the "pretty printing" of single- and double-quotes. In this attempt, I asked myself why we *ever* needed to do the `gsub` replacement of escaped double-quote characters with single-quote characters. I couldn't come up with a reason other than to make the tests more readable. Thus in this commit I've removed the custom implementation of `String#mocha_inspect` so it falls back to the default `String#inspect` implementation. As far as I can see the error messages are still sensibly formatted and by using the `%{}` string literal construction, I think the tests are still perfectly readable. I hope that this is a simpler and more robust way to solve the problems that @neonichu was seeing.
Superseded by #223 |
This is an alternative attempt at fixing the problem identified and addressed in #215 regarding the "pretty printing" of single- and double-quotes. In this attempt, I asked myself why we *ever* needed to do the `gsub` replacement of escaped double-quote characters with single-quote characters. I couldn't come up with a reason other than to make the tests more readable. Thus in this commit I've removed the custom implementation of `String#mocha_inspect` so it falls back to the default `String#inspect` implementation. As far as I can see the error messages are still sensibly formatted and by using the `%{}` string literal construction, I think the tests are still perfectly readable. I hope that this is a simpler and more robust way to solve the problems that @neonichu was seeing.
This is an alternative attempt at fixing the problem identified and addressed in #215 regarding the "pretty printing" of single- and double-quotes. In this attempt, I asked myself why we *ever* needed to do the `gsub` replacement of escaped double-quote characters with single-quote characters. I couldn't come up with a reason other than to make the tests more readable. Thus in this commit I've removed the custom implementation of `String#mocha_inspect` so it falls back to the default `String#inspect` implementation. As far as I can see the error messages are still sensibly formatted and by using the `%{}` string literal construction, I think the tests are still perfectly readable. I hope that this is a simpler and more robust way to solve the problems that @neonichu was seeing.
The pretty-printing of quotes from
inspect
was messing up actual quotes a bit, consider this example:before this PR:
after this PR:
So one now no longer gets confused by replaced double-quotes or incorrectly escaped single-quotes in the messages.