FailedExampleNotification message_lines without ANSI

29 views
Skip to first unread message

Dylan Reichstadt

unread,
Sep 15, 2017, 1:06:02 AM9/15/17
to rspec
Hey All,

I'm trying to export data from RSpec, including the failing lines of code. In the FailedExampleNotification, I noticed there were two methods:
  • message_lines
  • colorized_message_lines.
Despite the name differences, both of these methods look to return ANSI color characters, with message_lines slightly less (see below). I was expecting colorized_message_lines to do that, but not message_lines.

Is there a public method that exposes this data without the ANSI? I'll look to regex them out, but if there's another method that's more reliable, I would love to know.

Thanks!

RSpec Version: 3.6.0


notification.message_lines
=> ["Failure/Error: \e[0m\e[1;34;4mTestClass\e[0m.test_method",
 
"  expected to find css \"thisisatest\" but there were no matches"]

notification.colorized_message_lines
=> ["\e[31mFailure/Error: \e[0m\e[1;34;4mTestClass\e[0m.test_method\e[0m",
 
"\e[31m  expected to find css \"gjiegeij\" but there were no matches\e[0m"]


Jon Rowe

unread,
Sep 15, 2017, 1:46:41 AM9/15/17
to rs...@googlegroups.com
I believe you need to turn off code ray, as it’s colouring the snippets?

Jon Rowe
---------------------------

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3f5fd029-9bed-4dde-bac5-f76fe0d9ce9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Myron Marston

unread,
Sep 15, 2017, 1:49:45 AM9/15/17
to rs...@googlegroups.com
The message lines include two parts:
  • The english language parts (like "Failure/Error", and the failure message from the matcher)
  • The extracted code snippet (the `TestClass.test_method` part).
For the extracted code snippet, we use coderay to syntax highlight it if that gem can be loaded.  For the english language part, RSpec applies the color highlighting (but only when you call `colorized_message_lines`).

We should probably fix `message_lines` so that it doesn't apply coderay to the snippet, while `colorized_message_lines` should.  Can you open an issue on rspec-core about this?

Myron

--
You received this message because you are subscribed to the Google Groups "rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+unsubscribe@googlegroups.com.

Yuji Nakayama

unread,
Sep 15, 2017, 2:13:34 AM9/15/17
to rs...@googlegroups.com
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.

To post to this group, send email to rs...@googlegroups.com.

Dylan Reichstadt

unread,
Sep 15, 2017, 2:35:24 AM9/15/17
to rspec
Thanks Jon, Myron and Yuji for the response!
To unsubscribe from this group and stop receiving emails from it, send an email to rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/3f5fd029-9bed-4dde-bac5-f76fe0d9ce9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Chaffee

unread,
Sep 15, 2017, 8:21:52 AM9/15/17
to rs...@googlegroups.com
Also check out the JSON Formatter (--format j) which might be a
cleaner way to export from rspec than digging into the object API.

https://relishapp.com/rspec/rspec-core/docs/formatters/json-formatter
https://github.com/rspec/rspec-core/blob/master/lib/rspec/core/formatters/json_formatter.rb

Dylan Reichstadt

unread,
Sep 15, 2017, 7:29:23 PM9/15/17
to rspec
Thanks for the suggestion, Alex.

Unfortunately:
1) The JSON Formatter only dumps data at the end (dump_summary, profile). I'm looking for real time updating to my application that takes data
2) The failing line (information I've come to love when quick looking at failures) isn't included

I certainly looked at the JSON Formatter code to see if I could adapt it for the example_failed notification, but I'm assuming it would hit the same problem of the ANSI being within the failing line.

I've looked at a few examples, I'm going to use this regex which hopefully will catch all of my cases
\e\[[0-9;]*m
notification.message_lines[0].gsub(/\e\[[0-9;]*m/, '')
Reply all
Reply to author
Forward
0 new messages