How to color unit tests with lib minitest or Test:

2020-05-23 13:58发布

I would like to have unit tests output color in my dev environment. However, I can't make it work on Linux (Debian and Ubuntu). When I include the following libs:

require 'minitest/autorun'
require 'minitest/unit'
require 'minitest/pride'

I get:

/usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in `<top (required)>': undefined method `output' for MiniTest::Unit:Class (NoMethodError)

caused by the code:

MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output)

I have seen a working Rspec variant. Unfortunately, my Ruby knowledge is not enough to see differences.

7条回答
爷的心禁止访问
2楼-- · 2020-05-23 14:05

See https://github.com/tenderlove/purdytest/issues/1. It seems to be a known bug with the minitest version shipped with 1.9.2. For the others, adding

gem "minitest"

at the very top of your file did the trick.

查看更多
女痞
3楼-- · 2020-05-23 14:09

Give turn a whirl.

Add this to your Gemfile:

group :test do
  gem 'turn', :require => false
end
查看更多
干净又极端
4楼-- · 2020-05-23 14:16

simply add these lines to your test_helper.rb file after require 'rails/test_help'

require "minitest/reporters"
Minitest::Reporters.use!

in your gemfile add

gem 'minitest-reporters', '~> 1.0.7'

this will get your rake test to be in red and green, but it also brings up the backtrace. to get rid of all those extra backtrace logs add this to your gemfile then bundle:

gem 'mini_backtrace'

then in config/initializers/backtrace_silencers.rb add this line to cut all the extra rvm stuff

Rails.backtrace_cleaner.add_silencer { |line| line =~ /rvm/ }

hope that works for you, let me know if you need more details.

查看更多
The star\"
5楼-- · 2020-05-23 14:19

I currently use purdytest with 1.9.2

查看更多
地球回转人心会变
6楼-- · 2020-05-23 14:28

Try look at this post about using turn gem for nice looking and configurable output for minitest. http://rawonrails.blogspot.com/2012/01/better-minitest-output-with-turn-gem.html

查看更多
beautiful°
7楼-- · 2020-05-23 14:28
$ gem install mynyml-redgreen --source http://gemcutter.org

# in your test file
require 'redgreen'

redgreen and turn work nicely in conjunction with each other, by the way

查看更多
登录 后发表回答