-
-
Notifications
You must be signed in to change notification settings - Fork 753
Conversation
baf69af
to
43b6d69
Compare
This looks good to me barring a windows solution... Maybe we just make this unavailable in windows at the moment? |
Done. See my latest commit. |
SnippetExtractor might return non-parsable lines if the failure lines contain part of another expression: some_expression(
:foo
); this_is_the_failed_expression How does |
IMO, displaying |
I tried it with an expression that was more than the default max of 10 lines (so that the snippet was an incomplete ruby snippet) and it syntax highlighted it OK. It seems to handle non-parsable snippets OK.
That's a valid point, but:
Do you have a suggestion for an alternate way to do it? |
How about displaying the message only once using rspec-core/lib/rspec/core/notifications.rb Lines 247 to 251 in 19761e3
|
3535958
to
7d558b8
Compare
OK, I came up with a way to show the message at most once in the output. It's displayed as part of the summary. Here's what it looks like:
|
7d558b8
to
26373bd
Compare
👍 |
This is really kind of ugly... |
formatted = "\nFinished in #{formatted_duration} " \ | ||
formatted = "" | ||
if syntax_highlighting_unavailable | ||
formatted << "\nSyntax highlighting of failure snippets unavailable -- install the coderay gem to enable it.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to bring in coderay gem on all of my projects just for this feature, so I'm always going to get this message. That's kind of annoying I think.
It's a hard balance between advertising and getting out of the way!
We'd have to add a config flag for it, which seems possibly overkill.
Maybe leave it as is and I'll send you a PR if it's really getting to me ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a hard balance between advertising and getting out of the way!
We'd have to add a config flag for it, which seems possibly overkill.
Yep, I thought about the config flag, too, but yeah, that feels like overkill. We do already kinda have a config flag, anyway: --formatter
: you can configure a custom formatter that avoids displaying that message. That'd be way overkill as well, though.
One other thing to bear in mind: the syntax highlighter is only attempted to be used if there's a failure, which means reporter.syntax_highlighting_unavailable
is only set if there's a failure, which means that when there are no failures you won't get this message. That's intentional since I figure the user isn't missing out when everything passes. Hopefully that will make it less annoying for your case.
26373bd
to
3069a00
Compare
3069a00
to
b1b5bf4
Compare
The build is green and I think I've addressed the feedback. Anyone want to review it so we can merge it? |
I'm still not happy with the warning message, can we just remove it? |
Why has it never bothered you that we provide a similar message on every single code snippet in the HTML formatter? rspec-core/lib/rspec/core/formatters/html_snippet_extractor.rb Lines 10 to 14 in 78cf993
I think it's better to have the warning message and let users know they are missing out on the syntax highlighting than to have it be a hidden feature that users have to read the release blog post or changelog to learn about. |
Because that is constrained to the HTML formatter and doesn't pollute the reporter and every other formatter. |
To clarify, I'm bothered by the code quality, not the warning itself, it'd be better to build a way to add this sort of message to the summary in a generic fashion (as a public api) and use that to add this warning, than do this. |
I'm not sure what you have in mind as an improvement. Want to push a commit with your idea to this PR? |
Done. It wouldn't be too hard to add a generic "squash this message" setting to that commit either so you could disable certain types of messages. |
Thanks, @JonRowe, I do like the approach in general! |
Is there — or will there be — a way to disable the warning without installing |
With my approach I intend to add a way to suppress these messages On Tuesday, 10 November 2015, Tom Stuart [email protected] wrote:
|
I don't really want to start the process of adding a new config option for each bit of the formatter output that a user might want to silence. We already added one in #2007 and it's got me thinking about how we can do this more generically. @JonRowe may already be thinking of this, but what about: RSpec.configure do |c|
c.silence_formatter_message /Run options/
c.silence_formatter_message /coderay/
end |
I feel requiring users to add How about adding some comment to |
Maybe for now we should just remove the message altogether and just do syntax highlighting if coderay is available. We can document it in release notes and the release blog post. |
0b0d689
to
8696eca
Compare
8696eca
to
626cbec
Compare
I've made the changes you suggested @myronmarston, my intention is to add a config option to silence these, I don't think it's needed by default but I think the reporter should mention how to silence them, e.g...
|
626cbec
to
ff77be9
Compare
IMO, it seems odd to require the user to know what internal symbol is used to identify the message. If they can just call An API like |
In the interest of getting a release out, I'm leaning towards cutting the message about Thoughts? |
👍 |
Well we could merge this as is and add the silencing api in a point release :P |
That assumes we're all on the same page about the |
ff77be9
to
f21bb65
Compare
Well I've pulled the warning for now |
LGTM, merge when green. |
I may try to cut a release tonight. We'll see if I have time. (I have to put my kids to bed in a bit and that can take a very long time...) |
pull it and that leaves us an actual feature for 4.0 :P |
Implement syntax highlighting.
New in 4.0.0: Silencing all the error messages we added in 3.x? :P |
To make the upgrade to 4.0 compelling, we can add lots and lots of warnings in future 3.x releases! |
|
…ting Implement syntax highlighting.
This PR adds support for syntax highlighting the printed failure snippet when the
coderay
gem is available. Here's how it looks:The implementation is pretty straightforward but there is one hacky part about it: to work properly for the single-line case, where the snippet goes after
Failure/Error
, we have to insert an ANSI reset code (\e[0m
) at the start of the lines -- otherwise there was "leakage" of color changes. What I dislike about the solution is that the syntax highlighter assumes the exception presenter is going to put the snippet at the end of the line. With that assumption, the reset code solution works OK because there isn't any additional text from the presenter later in the line that should be colored a certain way that we are screwing up. But if the snippet was interpolated in the middle of a colored string, our current implementation would lead to some weirdness.I'm not sure what to do about it if anything, but thought it was worth noting.