Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Color in test output using latest Sublime Text 2 build #33

Closed
mhartl opened this Issue · 50 comments
@mhartl

These Sublime Text Ruby test functions are great, and I'm hoping to use them in the next edition of the Ruby on Rails Tutorial screencasts. Unfortunately, it looks like color test output might have been broken by the latest Sublime Text 2 beta (build 2165). Ever since upgrading, when I run the tests inside of Sublime Text the output console still appears, but the colors for passing/failing tests are gone. You can see what I mean in this screenshot. Any help getting this fixed before I start recording the next edition of the screencasts (in the next couple of weeks) would be greatly appreciated.

@fuzzylizard

In addition, when a test fails, you get the color codes in the output instead of the colors. As an example:

.......[31m[1mF[0m....
Finished in 1.770297 seconds.

  1) [31m[1mFailure[0m:
[34m[1mtest_needs_update_no_default_cost(CustomChargeSettingTest)[0m [[32m[1mtest/unit/custom_charge_setting_test.rb:51]:
[34m[1m<true> [1m[7mexpected but was[0m[0m
[34m[1m<false>.[0m
@mhartl

I can't reproduce the problem with color codes, but by downgrading to build 2139 I've confirmed that it's build 2165 that causes the colors to disappear.

@mhartl

I haven't been able to track down the bug, but I've found a kludgy workaround. The problem is that Sublime Text isn't even loading the theme file for the RubyTest widget. Here's the hack:

Edit the file "Theme - Default/Widget.sublime-settings" in the Library/Application\ Support/Sublime\ Text\ 2/Packages directory:

$ subl "Theme - Default/Widget.sublime-settings" 

In that file, change

"color_scheme": "Packages/Theme - Default/Widgets.stTheme"

to

"color_scheme": "Packages/RubyTest/TestConsole.tmTheme"

By changing the default color theme, this probably screws up other widgets, but since the RubyTest widget is the only one I currently use I can live with that.

@gs
Collaborator
gs commented

That looks good now!

Thanks for sorting this out.

Br,
Grzegorz

@gs gs closed this
@mediafinger

I am on Build 2178, did the steps Michael recommended, restarted Sublime from the command line - and still was stucked with black on white text.

As I am using the Soda Light Theme, I had to edit the according file:

subl ~/Library/Application Support/Sublime Text 2/Packages/Theme - Soda/Soda Light/Widget\ -\ Soda\ Light.sublime-settings

And finally I got a colorful output.

@KensoDev

@mhartl comment fixed it for me, thanks

@jondkinney

Hmmm, neither editing the Default theme widget settings or the light or dark soda theme widget settings would get the color to show up in the text execution window for me... odd... I'm on the latest dev build 2180. Did that break even this fix?

@mediafinger

As of today I am also running build 2180 - the colored console output is still fine.

@jondkinney

Here's a screenshot of my settings files and a test I tried to run http://cl.ly/ENTr. I found that the RubyTest settings file has --no-color specified which would seem to be the culprit, so I edited the prefs file to remove that flag and it was still just white text in the test console. Then I added the --color flag explicitly and now I'm seeing the escaped color output mentioned above as well. Any help would be greatly appreciated! Thanks!

@jondkinney

I even tried using AppZapper and removing all traces of Sublime Text 2 and re-installing the latest dev build, then following the instructions here and still can't get it to work with either the default theme or soda. Bummer...

@jondkinney

Wow... I even reverted to the build Michael said it worked on 2139 and didn't change anything except for installing package control and RubyTest and Cucumber, then tried running this test... white text still. http://cl.ly/EMra Sorry to be such a bother, I just would very much like to get this working!!

@jondkinney

I guess the syntax highlighting just doesn't yet support Cucumber because I was able to get it working in a generic RSpec file. Any plans to add Cucumber support for syntax coloring of output? http://cl.ly/ENEx

@gs
Collaborator
gs commented

added colors for cucumber test output http://cl.ly/1H3F2a001J2c2z3H1j3k

@jondkinney

Hi guys, I added some additional coloring in a pull request but could use some help to determine if the coloring can be improved. Please see the open pull request here - https://github.com/maltize/sublime-text-2-ruby-tests/pulls

Thanks!

@pdtpatrick

I'm on Build 2181 and Coloring still does not work. I've tried all the solutions in here.

http://cl.ly/2X0U092p2M140B0Q1f3S

@gs
Collaborator
gs commented

Are you using Soda theme or some other themes?

Please refer to #33 (comment) . This solves standard problems with coloring.

Br,
Grzegorz

@pdtpatrick

{
"color_scheme": "Packages/Color Scheme - Default/Monokai Bright.tmTheme",
"font_size": 18.0,
"ignored_packages":
[
],
"soda_classic_tabs": true,
"tab_size": 4,
"theme": "Nil.sublime-theme",
"translate_tabs_to_spaces": true,
"use_tab_stops": true
}

@adamwiggall

I have been struggling with this all afternoon. I have resolved it by going to Preferences -> Settings -> User and deleting the 'theme' entry (which was set to the Soda Light theme). Not sure what the difference is between the 'theme' and the 'color_scheme' is, but all that changed for me was the testing output coloring.

I had followed the instructions from #33 (comment) prior to doing this.

@mps

@mhartl your fix worked for me, thanks!

@gs
Collaborator
gs commented

@pdtpatrick just remove "theme": "Nil.sublime-theme" from your config file... hope this solve issue
@adamwiggall 'theme' can style sublime, different menu colors, and so on...
'color_scheme' define colors in edit mode, highlights :)

Hope that give some hint.

Br,
Grzegorz

@ritchiey

Thanks for that, @mhartl. Worked for me but I had to edit my .rspec file and remove the --tty to get rid of the ESC escape characters that were appearing in the output.

@phallguy

@adamwiggall Just change the Widget - Soda Light.sublime-settings file in Packages/Theme - Soda/Soda Light instead and you'll get both the Soda theme and the colored console.

@BobWalsh

@adamwiggall Doing what you did worked for me as well! Thanks!

@BobWalsh

And having tried ALL of the above fixes, I'd bet there's a conflict between several ways that a "widget" can be configured.

@BobWalsh

If you are using one of the soda themes, the rubytest results window (a ST widget) loses color - but if you copy the settings from RubyTest/widget.sublime-settings into (for example) Soda Dark/Widget - Soda Dark.sublime-settings you can have rspec color and Soda [Dark/light]

@levity

I copied RubyTest/Widget.sublime-settings into User/ and that worked for me, since I'm not using color for any other widgets.

@dlucca

@mediafinger comment six month ago solve it for me! I'm also using the Soda Theme thanks!!!

@neocsr

@levity copying Widget.sublime-settings into User also worked for me.

@wanwu

And am using Railcasts theme + Followed @mhartl's fix above.

Then I commented out Soda Light.sublime-theme in the config file:

 // "theme": "Soda Light.sublime-theme",

That got me the white on black test console & colors working for RubyTests.

@fredwu

If you're using a custom theme (such as Soda Light/Dark), make sure in Widget - name-of-your-them.sublime-settings you also have the following:

"syntax": "Packages/RubyTest/TestConsole.tmLanguage"
@gja
Collaborator

This should also get fixed if you merge in #99. I explicitly set the color theme.

@jeremykay

I've tried all of these and I'm not getting color highlighting. I have ST version 201 build 2217. I'm using the Monokai theme.
My Widget.sublime-settings file looks like:

{

  "color_scheme": "Packages/RubyTest/TestConsole.tmTheme"
} 

And my Preferences.sublime-settings looks like:

{
    "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
    "font_size": 14.0,
    "ignored_packages":
    [
        "Vintage"
    ],
    "syntax": "Packages/RubyTest/TestConsole.tmLanguage"
}

It'd be nice if I could get it to work!

@joshukraine

Hi all,

Just getting my system set up today on Lesson 3 of the Rails Tutorial, and I couldn't get the custom colors to work either. I'm using build 2217 of Sublime Text 2, but when I followed the steps from @mhartl to swap in his CustomTestConsole.tmTheme, it didn't work. That is, I had the default colors (which render the failures as pink) but I wanted to get it to red as demonstrated in the screencasts. Worked on it for several hours and finally found a solution.

It turns out that, at least for me, that a file called run_ruby_test.py was overwriting any changes I made to Theme - Default/Widget.sublime-settings.

So here's essentially what I did.

1) Copy CustomTestConsole.tmTheme to ~/Library/Application Support/Sublime Text 2/Packages/RubyTest/CustomTestConsole.tmTheme.

2) Edit run_ruby_test.py so that all references to Packages/RubyTest/TestConsole.hidden-tmTheme are changed to Packages/RubyTest/CustomTestConsole.tmTheme.

Once I did this, it picked up the custom colors immediately. Didn't even have to restart Sublime. :) Hope that helps!

@JohnMorales

I realize I'm commenting to a closed case but I followed the workaround, and I'm closer, but still broken.

@mhartl's 'kludgy workaround' did give me colors (which I didn't have before..thanks!) but I'm still getting what looks like color escape codes showing up.

fyi I'm using build 2217 on a mac.

What I've done is edited the Theme - Default/Widget.sublime-settings to point to "Packages/RubyTest/TestConsole.hidden-tmTheme" (since that's the only tmTheme file)

Here's what I'm at:
Screen Shot 2012-12-16 at 11 15 52 AM

@javiercr

I got the same problem than @JohnMorales, got colors but still those horrible "ESC" characters too.

@javiercr

Actually just fixed the problem by editing my cucumber.yml so it doesn't print colors:

Change cucumber.yml from:
std_opts = "--strict --tags ~@wip"
to
std_opts = "--no-color --strict --tags ~@wip"

Now I have the colors working perfectly. It seems that maybe cucumber was adding colors and then RubyTest was adding colors again causing those ESC characters.

@Jpunt

I've made TestConsole.hidden-tmTheme comparable with Monokai and Espresso Soda, for those who can't stand differences between windows (like me):

https://gist.github.com/4412127
Screen Shot 2012-12-30 at 12 37 10

https://gist.github.com/4412419
Screen Shot 2012-12-30 at 12 37 44

@virtix virtix referenced this issue in mxunit/sublime-text-2-mxunit
Closed

New Output View #4

@davidcelis

I've tried all of the above workarounds, and none of them work for me. I'm using build 2220 on OS X Mountain Lion. These are tests running under Ruby/Rails/Zeus:

@karolxavierleite

I had the same problem as JasonMorales and javiercr.

I'm using build 2217 on a linux (Ubuntu).

javiercr's solution works fine to me! Just change the color option on cucumber.yml to "no-color"

Thanks a lot. :+1:

Before and after :-)

color
no-color

@javiercr

Glad it worked for you @karolxavierleite!

@georgiee

I had the same problem. RubyTest was not the problem, as it worked in the default setup without any rails preloader.
In my setup using "spin" to preload rails and speed up testing I got those escape sequences. It`s not spin to blame but it's a nice place to fix.
This following regex strips out ansi sequences and the output looks nice again. I think this problem could be solved inside RubyTest by running the regex in the python script executing the specs. Other preload scenarios (spork, zeus) could be fixed with this approach. Anyway here the regex and a link to my spin pull request.

Pull request: jstorimer/spin#80

Regex:

output = output.gsub(/\e\[[^m]*m/, '')

Here my fixed output.
screen shot 2013-06-05 at 11 53 14
before

@dsandstrom dsandstrom referenced this issue in jfelchner/ruby-progressbar
Closed

New line spam on Windows #29

@gucki

I'd also recommend to either support/ interpret ansi sequences or just strip them as @georgiee suggested. :+1:

@imton

Ok. None of this worked for me. Out of nothing I got the black&white bug. This was driving me crazing, and I found that adding the following to my RubyTest.sublime-settings, solved me the problem.

"theme": "Packages/RubyTest/TestConsole.hidden-tmTheme"

Hope it works to others.
ton.

@ryandeussing

@imton high five!

Furthermore, swapping out the contents of Packages/RubyTest/TestConsole.hidden-tmTheme with CustomTestConsole.tmTheme replaces pink with red for failing tests.

@imton

Ok. I want to cry. Suddenly I've got the black/white problem again. my previous setting seems to be not working anymore. :(

So far the alternative I've found is to replace the "Theme - Default" setting to "Packages/RubyTest/TestConsole.hidden-tmTheme"

@gs
Collaborator
gs commented

hey, we dont need any more hacking.

colors should be at place, check if you have path in your RubyTest.sublime-settings.

Also be sure to restart sublime few times..there might be caching problem :)

Good luck

@ka8725

I had this issue with rspec. So my solution was do not use custom format option. I used to format option and it was the cause of the issue

@dsandstrom

@gs Colors seem to be working better, Thanks. However, a couple things don't seem to be working right.

If all tests past, the dots are green
screenshot from 2013-08-14 16 14 35

But if there is a fail, the dots turn white. The F is correctly pink, though.
screenshot from 2013-08-14 16 14 18

Also a pending, turns the dots white.
screenshot from 2013-08-14 16 15 31

I realize that these are just minor details, but just wanted you to know.

@snowblink snowblink referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@laggingreflex laggingreflex referenced this issue in misfo/Shell-Turtlestein
Closed

FR: Colors! #9

@arefaslani

For get rid of ugly Esc characters(in rspec output), just remove --color from .rspec file.

@csalvato

This is still not working for me. Tried all the suggestions above but nothing seems to be working.

With Minitest Reporters On:
screen shot 2015-01-18 at 7 42 01 pm
screen shot 2015-01-18 at 7 41 21 pm

With Minitest Reporters Off:
screen shot 2015-01-18 at 7 42 45 pm
screen shot 2015-01-18 at 7 43 07 pm

Using Sublime Text 2 Build 2221 and Rails 4.2.0.

EDIT: I also don't know what you mean by "check if you have path in your RubyTest.sublime-settings." @gs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.