In rails is it possible to get colour highlighting for the rake test command?

匿名 (未验证) 提交于 2019-12-03 02:52:02

问题:

When running 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 

回答1:

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.



回答2:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!