Rails colour highlighting for the Test::Unit/rake command?
Asked Answered
D

3

9

When running test/unit using the rake test command from the terminal within a rails 3 project directory, the test result output is not coloured. Hence, it cannot be interpreted at a glance.

Is there a way of getting colourised output for the results, as you can get in rspec?

>rspec --colour
Derwood answered 21/10, 2010 at 21:24 Comment(3)
why just use the rspec command ?Melindamelinde
I went with the defaults and am using test/unit.Derwood
The answers with the highest votes are abandoned projects the only answer with active project is minitest-reporters belowBullion
D
10

Yes, you can use the redgreen gem. Include it in your gemfile:

group :development, :test do
  gem 'redgreen'
end

And that's all you need for ruby 1.8. If you're using 1.9, there's a workaround. add the test-unit gem:

group :development, :test do
  gem 'redgreen'
  gem 'test-unit', '1.2.3
end

It's not perfect with 1.9 - test-unit seems to run an empty test suite after every rake task or generator call, which is harmless but annoying.

Dipterous answered 21/10, 2010 at 22:8 Comment(2)
OK, finally got this working! Thanks for the answer. You need that second gem (test-unit) for 1.9 (.2 in my case). Still prefer the output from gem turn, but this looks good too. Why do you put them in the development group?Riggins
In my case, removing the redgreen and test-unit gem from the development group in the Gemfile avoids the unnecesary test suite run.Paramedic
R
20

I discovered that redgreen was abandoned years ago, and found this solution which works well and requires no script hacking. The output, however, shows which test is being run in real time. So it is a lot longer than built in test output. It does have nice colors.

http://rubygems.org/gems/turn

In my Gemfile:

group :test do
  gem 'turn'
end

Then run:

$ bundle install
$ rake test

The gem 'turn' works great. The caveat is that it doesn't seem to work with Mocha, due to monkey-patching issues. If you are using Mocha, you can use the redgreen gem. See instructions above in the approved answer for this question.

Riggins answered 8/6, 2011 at 21:2 Comment(4)
gem turn helps a lot. it works with Rails 4.0 + Ruby 2.0. I just tested it right now.Tillio
Awesome thanks, I like the fact that with 3 lines of code you get decent colors :-)Maxentia
This looked promising but the author decided to deprecate it and doesn't work with ruby 4.2.0 out of the box anymoreGeneratrix
@Generatrix - Wow, this answer is old. I don't use Test Unit anymore, but perhaps a gem is no longer required? Check this SO question: #15029571Riggins
D
10

Yes, you can use the redgreen gem. Include it in your gemfile:

group :development, :test do
  gem 'redgreen'
end

And that's all you need for ruby 1.8. If you're using 1.9, there's a workaround. add the test-unit gem:

group :development, :test do
  gem 'redgreen'
  gem 'test-unit', '1.2.3
end

It's not perfect with 1.9 - test-unit seems to run an empty test suite after every rake task or generator call, which is harmless but annoying.

Dipterous answered 21/10, 2010 at 22:8 Comment(2)
OK, finally got this working! Thanks for the answer. You need that second gem (test-unit) for 1.9 (.2 in my case). Still prefer the output from gem turn, but this looks good too. Why do you put them in the development group?Riggins
In my case, removing the redgreen and test-unit gem from the development group in the Gemfile avoids the unnecesary test suite run.Paramedic
B
3

I am working on Rails 5.1 / minitest and I was also searching for a solution to make the reporting color. None of these test::unit solutions are working, so I googled and saw this solution. Just add the following:

# Gemfile
gem 'minitest-reporters'

# test/test_helper.rb
require "minitest/reporters"
Minitest::Reporters.use!

Github: minitest-reporters

Brahear answered 4/1, 2019 at 17:15 Comment(1)
Here is some more info on changing default reporters: github.com/kern/minitest-reportersBeaux

© 2022 - 2024 — McMap. All rights reserved.