-
-
Notifications
You must be signed in to change notification settings - Fork 760
Extract multiple failed lines by parsing Ruby #2083
Conversation
e6c48db
to
6ff075b
Compare
@@ -59,7 +59,8 @@ Feature: Aggregating Failures | |||
# ./spec/use_block_form_spec.rb:18 | |||
# ./spec/use_block_form_spec.rb:10 | |||
|
|||
1.1.1) Failure/Error: expect(response.status).to eq(200) | |||
1.1.1) Failure/Error: | |||
expect(response.status).to eq(200) |
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.
For multiline snippets it should certainly be started on the next line but for single line snippets I think I prefer it to be on the same line like it was before. It cuts down on unnecessary churn in this PR if you don't have to change all the expectations about the failure formatting and keeping it to one line means the failure output doesn't take up as much vertical space, which is always nice.
How much effort would it be to keep single-line failures on the same line as Failure/Error:
?
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.
Actually that's what I was unsure about. I made the snippets be always on the next line for consistency, but it's not a strong opinion. I'll make change to do so.
By the way there's another concern about putting the snippets on the next line. There's no problem when an RSpec's exception has a message starting with a blank line:
1.1) Failure/Error:
expect(response.status).to eq(200)
expected: 200
got: 404
(compared using ==)
# ./spec/nested_failure_aggregation_spec.rb:7
However it's hard to read when there's no blank line:
1.2.2) Failure/Error:
expect(response.headers).to include("Content-Length" => "21")
expected {"Content-Type" => "text/plain"} to include {"Content-Length" => "21"}
Diff:
@@ -1,2 +1,2 @@
-[{"Content-Length"=>"21"}]
+"Content-Type" => "text/plain",
# ./spec/nested_failure_aggregation_spec.rb:11
Maybe we should always put a blank line in ExceptionPresenter and remove the blank line in exception message?
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.
Oh you had already mentioned it :) #2083 (comment)
I'm really excited about this feature, @yujinakayama -- thanks for developing it! I'm not done with my review yet but need to head to bed. For now I wanted to share a few general thoughts:
expect(1).to eq(1); expect(2).to eq(1); expect(2).to eq(2) This is a contrived example obviously... |
I noticed a case where this didn't work as I expect: expect {
expect("foo").to start_with("a").and end_with("z")
}.to fail_with(dedent <<-EOS)
| expected "fo" to start with "a"
|
|...and:
|
| expected "foo" to end with "z"
EOS (This is a slightly modified spec from rspec-expectations). The extracted snippet is:
Notice it's missing the heredoc. It would be nice if that was included. In addition, in the full output the snippet is crammed right next to the failure message:
I think it would be easier if there was an extra line break after the snippet:
Or perhaps on both sides of the snippet:
|
032acb1
to
36c4334
Compare
36c4334
to
232ba6b
Compare
20067be
to
62d79b4
Compare
@yujinakayama -- I went ahead and addressed #1991 via #2088 as that will help to give 3.4 a nice "vastly improved failure output" theme when combined with this PR and rspec/rspec-expectations#859. I don't think it complicates this PR but there might be a slight merge conflict when one or the other PR gets merged. |
62d79b4
to
b6973b9
Compare
Now I'm trying the improve the format of message lines and thinking of it in various cases. Here are some failure messages with the current implementation in this branch:
The failure 2 is obviously unreadble. Also, the formats are inconsistent a bit. To address these issues, I'm thinking of the following two formats: A: Less lines when possible
B: Consistent format
What do you think? |
How about option (C):
(In other words, the only time there wouldn't be a blank line is when both are single line strings). |
BTW, I merged #2088 so you may want to rebase. |
be71fe5
to
edc8e4b
Compare
❤️ This looks great to me! It'll need a changelog entry but that can happen post-merge. Want to do the honors, @yujinakayama? |
... by using Array for lines until final rendering.
It allows detail or failure/error line to be used as the first line by omitting preceding lines, rather than specifying content of detail or failure/error as description.
650411d
to
f37093b
Compare
Added changelog entries 👌 |
Merge when green! :) |
BTW I'll try code highlight with CodeRay and hopefully it'll be merged before 3.4 release |
Extract multiple failed lines by parsing Ruby
Sounds great! FWIW, I played around with it a bit a few days ago and I pushed my spike up in 170b28e. Feel free to use any (or none) of that in whatever you come up with. |
The output formatting changed in rspec/rspec-core#2083, but we didn’t realize it broke the cukes here.
The output formatting changed in rspec/rspec-core#2083, but we didn’t realize it broke the cukes here.
The output formatting changed in rspec/rspec-core#2083, but we didn’t realize it broke the cukes here.
RSpec changed how it detects source lines to print in rspec/rspec-core#2088, which necessitates us configuring `project_source_dirs` for our specs. (This should not affect end-users). In addition, we now print multi-line code snippets as of rspec/rspec-core#2083. Multiline snippets are not printed on the same line as `Failure/Error:` so our regex has to be updated to accommodate a line break.
RSpec changed how it detects source lines to print in rspec/rspec-core#2088, which necessitates us configuring `project_source_dirs` for our specs. (This should not affect end-users). In addition, we now print multi-line code snippets as of rspec/rspec-core#2083. Multiline snippets are not printed on the same line as `Failure/Error:` so our regex has to be updated to accommodate a line break.
…ing-ruby Extract multiple failed lines by parsing Ruby
The output formatting changed in rspec/rspec-core#2083, but we didn’t realize it broke the cukes here. --- This commit was imported from rspec/rspec-expectations@f4c0fea.
For rspec/rspec-expectations#790
With the following failing example:
Before
After