Rspec-core: rspec syntax coloring in github

Created on 2 Aug 2017  路  1Comment  路  Source: rspec/rspec-core

I was wondering if there was a github formatter that would give rspec output color, so that something like the following would show green and red in the right places:

  Spec
    works

Finished in 0.00107 seconds (files took 0.03723 seconds to load)
1 example, 0 failures

I asked github about it and they said:

For syntax highlighting, we use the open source tool Linguist to provide language detection support on GitHub 1. Before we can perform syntax highlighting for a language, it needs to have an open source Textmate-style language grammar. These grammars also provide syntax highlighting for the Textmate, Sublime Text, and Atom editors 2.

Once you've found or created a grammar you can submit it to linguist by following this guide:

https://github.com/github/linguist/blob/master/CONTRIBUTING.md

Has anyone ever thought about doing something like this?

Most helpful comment

Hi @tansaku! Good to see you here :).

What you're asking for is an interesting, useful idea, but I'm not sure how feasible it is. Consider that RSpec output isn't a syntax-highlightable language per-se; it's simply shell output. In a normal language, there are token that have specific meaning (e.g. [, ", {, etc) that a syntax highlighter can parse to know what part of the language a specific bit of text is. RSpec's output isn't like that; whether or not a line should render in a specific color depends on whether or not the string is an example group description or an example description, and whether or not it ran, and if it ran, whether it passed, failed or is pending. RSpec's formatter has all that info when printing to your console, but it does not encode all that info in what is printed, so I don't think there's a way for a syntax highlighter to infer it from the printed plain text.

I think a better route is to find a way to get github to honor ANSI escape sequences (which is what RSpec uses to color its output in the terminal). If you run rspec --force-color | pbcopy (on OSX; on other OSs, you'll need to use something different than pbcopy), you'll get the output with all the ANSI escape codes included. That provides all the info to color each part of the output appropriately, so it's just a matter of getting github to honor that. If you could get that to work, it would have the bonus of providing highlighting the output for any terminal tool, which would be pretty useful.

That said, it looks like this has been discussed (and decided against) in github/linguist#2528, so maybe it's not feasible for linguist to handle ANSI escape codes for some reason.

Anyhow, I'm going to close this as I don't think there's anything actionable for the RSpec maintainers to do here, but we can continue the conversation even after the issue is in the closed state.

>All comments

Hi @tansaku! Good to see you here :).

What you're asking for is an interesting, useful idea, but I'm not sure how feasible it is. Consider that RSpec output isn't a syntax-highlightable language per-se; it's simply shell output. In a normal language, there are token that have specific meaning (e.g. [, ", {, etc) that a syntax highlighter can parse to know what part of the language a specific bit of text is. RSpec's output isn't like that; whether or not a line should render in a specific color depends on whether or not the string is an example group description or an example description, and whether or not it ran, and if it ran, whether it passed, failed or is pending. RSpec's formatter has all that info when printing to your console, but it does not encode all that info in what is printed, so I don't think there's a way for a syntax highlighter to infer it from the printed plain text.

I think a better route is to find a way to get github to honor ANSI escape sequences (which is what RSpec uses to color its output in the terminal). If you run rspec --force-color | pbcopy (on OSX; on other OSs, you'll need to use something different than pbcopy), you'll get the output with all the ANSI escape codes included. That provides all the info to color each part of the output appropriately, so it's just a matter of getting github to honor that. If you could get that to work, it would have the bonus of providing highlighting the output for any terminal tool, which would be pretty useful.

That said, it looks like this has been discussed (and decided against) in github/linguist#2528, so maybe it's not feasible for linguist to handle ANSI escape codes for some reason.

Anyhow, I'm going to close this as I don't think there's anything actionable for the RSpec maintainers to do here, but we can continue the conversation even after the issue is in the closed state.

Was this page helpful?
0 / 5 - 0 ratings